Salesforce Filter Logic Syntax: A How-To Guide
In this article
Salesforce filter logic syntax lets you combine multiple filter conditions with AND, OR, and NOT to control exactly which records appear in a report, list view, or dashboard. The syntax uses numbers to reference each filter row (1, 2, 3, etc.) and parentheses to group them. For example, 1 AND (2 OR 3) means the first condition must be true, and either the second or third must also be true. You enter this logic in the Filter Logic field, which appears after you add at least two filters. This guide walks you through using it correctly, avoiding common pitfalls, and troubleshooting when results don't match expectations.
What You'll Need
- A Salesforce account with permission to create or edit reports, list views, or dashboards.
- At least two filter conditions added to your report or list view (filter logic only becomes available after the second filter).
- Basic familiarity with AND/OR logic (optional but helpful).
Step-by-Step
- Open your report or list view. Navigate to the Reports tab or the object's list view you want to filter. Click New Report or edit an existing one.
- Add filter conditions. In the Filters panel, add at least two filters. For example: Status equals Open and Amount greater than 1000. Each filter you add is automatically assigned a number (1, 2, 3, etc.) in the order they appear.
- Locate the Filter Logic field. After adding the second filter, a Filter Logic text box appears below the filter list. It may be collapsed under a link like Add Filter Logic or shown directly. Click it to edit.
- Enter your logic expression. Use the numbers corresponding to your filters, combined with operators:
AND,OR,NOT, and parentheses. For example, to require filter 1 AND (filter 2 OR filter 3), type:1 AND (2 OR 3). Do not use commas or other separators; use spaces around operators. - Validate your syntax. Salesforce will show an error if the logic is invalid (e.g., mismatched parentheses or referencing a non-existent filter number). Click Apply or Run to test. The report preview updates to show records matching your logic.
- Save and share. Once the results look correct, save the report or list view. The filter logic is saved with it and will apply whenever the report is run.
Note: Menu labels and the exact location of the Filter Logic field can differ slightly between Salesforce Classic and Lightning Experience, and across different objects. The steps above apply to Lightning Experience, which is the current interface.
Common Mistakes
- Forgetting parentheses. Without parentheses, AND has higher precedence than OR, which can produce unexpected results. Always group OR conditions explicitly.
- Using filter numbers that don't exist. If you delete a filter, the remaining filters are renumbered. Update your logic accordingly.
- Mixing up AND/OR. Remember: AND requires all conditions to be true; OR requires at least one. A common error is using AND when you mean OR, leading to too few results.
- Not using the NOT operator correctly. NOT negates the following condition or group. For example,
NOT (1 OR 2)excludes records that match either filter 1 or 2. - Assuming filter logic works with a single filter. The Filter Logic field only appears when you have two or more filters. With one filter, the logic is simply that filter.
Tips
- Start simple: test each filter individually before combining them with logic.
- Use parentheses liberally to make your intent clear, even when not strictly required.
- Keep filter logic readable by breaking long expressions into multiple lines if the editor allows (though Salesforce typically accepts a single line).
- Document your logic in the report description so others understand the intent.
- Remember that filter logic applies only to the filters in the current report or list view; it does not affect other reports.
Troubleshooting
If your report returns no records or unexpected results, check these common issues:
- Syntax error message: Review your expression for missing parentheses, misspelled operators, or invalid filter numbers. Salesforce will highlight the error.
- Logic seems correct but results are wrong: Verify that each filter condition is set up as intended. Sometimes a filter value is incorrect (e.g., a picklist value that doesn't exist).
- Filter numbers changed: If you added or removed filters after writing logic, the numbers may have shifted. Re-edit the logic to match the current filter order.
- Report times out or is slow: Complex logic with many OR conditions can impact performance. Consider simplifying or using a custom report type.
- Filter logic field is missing: Ensure you have at least two filters. If you still don't see it, check your Salesforce edition or permissions; some older or restricted editions may have limitations.
If problems persist, try recreating the report from scratch or contacting your Salesforce administrator.
Frequently Asked Questions
Can I use filter logic in list views?
Yes, list views support filter logic in the same way as reports. The Filter Logic field appears after you add multiple filters.
What operators are supported?
Salesforce supports AND, OR, and NOT. Parentheses are used for grouping. The operators are not case-sensitive, but uppercase is conventional.
How do I reference a filter in the logic?
Each filter is numbered sequentially starting from 1, based on its position in the filter list. Use that number in your expression.
Can I nest parentheses?
Yes, you can nest parentheses to create complex logic, such as 1 AND (2 OR (3 AND 4)). Just ensure they are balanced.
Does filter logic work with cross-object filters?
Yes, filter logic applies to all filters in the report, including cross-object filters, as long as they are numbered in the list.
What happens if I leave the Filter Logic field blank?
If left blank, Salesforce applies the default logic: all filters are combined with AND. That means every filter must be true for a record to be included.