Salesforce Cross Filter Logic allows administrators to restrict the records visible in a list view or report tab based on a related record’s field value, effectively enforcing data segregation without complex coding. Before you begin, ensure you have the "Customize Application" permission and understand that this feature is only available in Salesforce Enterprise, Performance, Unlimited, and Developer editions. It is not supported in the Essentials or Group editions. You must also have a defined object relationship (Lookup or Master-Detail) between the two objects you intend to filter on.
What You'll Need
- Administrator Profile: A user with the "Customize Application" permission in your Salesforce org.
- Valid Object Relationships: A relationship field (Lookup or Master-Detail) connecting the primary object to the secondary object you want to filter by.
- Target Object: The object you want to restrict visibility for (e.g., Cases, Contacts, or Opportunities).
- Permission Set (Optional): If you want to apply the filter to users on a specific permission set rather than their profile, ensure the Cross Object Filter permission is added to that set.
Step-by-Step
- Navigate to the Cross Object Filters tab. In Salesforce Classic, click the App Launcher (the nine dots in the top right corner) and select Setup. In the Quick Find box, type "Cross Object Filters" and select it. In Salesforce Lightning Experience, go to Setup (the gear icon) and use the Quick Find box to search for "Cross Object Filters".
- Create a new Cross Object Filter. On the Cross Object Filters list page, click the New Cross Object Filter button at the top right. This will open the filter definition wizard.
- Configure the Primary Object. In the first section of the wizard, select the Primary Object. This is the object whose records you want to filter. For example, if you want to restrict visibility of Cases, select "Case". Select the Filter Type. You generally have two options: Filter SObjects (which applies to the entire object) or Filter List Views (which applies to specific list views you define later). For most applications, Filter SObjects is the correct choice.
- Define the Relationship Filter. This is the core logic of the Cross Object Filter. You must select a Relationship that connects your primary object to a related object. For instance, if you are filtering Cases, you might select the Account object via a lookup relationship. Once the relationship is selected, choose the Field on the related object that you want to filter by. Common choices include OwnerId (to show only records belonging to the current user) or RecordTypeId (to segregate data by territory or product type).
- Set the Filter Criteria. In the criteria section, you define exactly how the relationship field must match. Select the Operator (e.g., Equals, Not Equals) and enter the Value or field reference. If you chose OwnerId as your field, you would select Equals and then use the {!$User.Id} variable to automatically match the logged-in user. If you are filtering by a custom field on the related object, you can select that field from the list.
- Assign the Filter to Profiles. The next screen allows you to assign the filter to specific Profiles. Profiles determine the level of access a user has. Click Add to select the profiles you want to apply this logic to. You can also assign the filter to a Permission Set if you prefer a more granular or temporary assignment method. Select the profiles and click Next.
- Assign the Filter to List Views (Optional). If you chose Filter List Views in step 3, or if you want to apply the filter to specific views, you will now select the list views. Select the list views on the related object to which you want to link this Cross Object Filter. For example, you might link a filter for Accounts to a list view of Cases. Click Next.
- Review and Save. On the final screen, review all the details you have entered: the primary object, the relationship, the criteria, and the assigned profiles. Ensure the logic makes sense for your security requirements. Once you are confident, click Save. The Cross Object Filter is now active.
- Test the Filter. Log in as a user who is assigned the profile with the new filter. Navigate to the object you filtered (e.g., Cases). You should see only the records that match the criteria defined in the filter. Try logging in as a user without the profile or with a different filter; they should see all records or a different set of records.
Common Mistakes
- Using the Wrong Filter Type: A frequent error is choosing Filter List Views when the goal is to restrict the entire object. Filter List Views only apply to specific views; they do not hide records from the global search or other default views. Use Filter SObjects for a blanket restriction.
- Incorrect Relationship Selection: You must select a relationship that exists on the primary object. If you are filtering Cases, you cannot filter by a field on the Contact object unless there is a direct relationship between Case and Contact. Ensure you select the correct lookup or master-detail field.
- Not Using {!$User.Id}: When filtering by the owner of the related record, simply typing "Owner ID" will not work. You must use the Salesforce variable {!$User.Id} or {!$User.Name} so that the filter dynamically updates for each user who logs in.
- Assigning to the Wrong Profiles: It is easy to overlook assigning the filter to a profile that actually needs it. Always double-check the profile assignment list to ensure the target users are included.
Tips
- Combine with Sharing Rules: Cross Object Filters are a powerful tool, but they work best when combined with standard Sharing Rules. Use sharing rules to grant access to specific users who should see more data, and use Cross Object Filters to hide that data from everyone else.
- Use Custom Fields for Flexibility: If you need to filter by a value that changes frequently, consider using a custom field on the related object. This allows you to update the filter criteria without modifying the Cross Object Filter definition itself.
- Check for Dependency: Be aware that Cross Object Filters can interact with other security settings. If a user has a role hierarchy that grants access to a record, the Cross Object Filter will not override the role hierarchy. The filter takes precedence only if the user has no direct access to the record.
- Document the Logic: Because Cross Object Filters can be complex, it is important to document the logic. Keep a record of which profiles have which filters and what the criteria are. This makes it easier to troubleshoot issues or make changes in the future.
Troubleshooting
- Filter is not applied: If the filter is not working, first check that the profile is correctly assigned. Ensure the user logging in actually has the profile. Also, verify that the relationship field exists and is populated on the related records. If the related field is null, the filter criteria (e.g., Equals a value) will not match.
- Too many records are visible: If you see more records than expected, check the filter criteria. Ensure you are not using an "Equals" operator when you intended to use a "Not Equals" operator. Also, check if there is a sharing rule that is granting access to the records.
- Filter applies to the wrong users: If the filter is applying to users who should not see it, check the profile assignments. Ensure that the profiles assigned to the filter do not include the profiles of the users you want to exclude.
- Filter is not saving: If the filter fails to save, check for validation rules or Apex triggers on the objects involved. A validation rule or trigger might be preventing the filter from being created. Also, ensure that you have the necessary permissions to create Cross Object Filters.
- Global Search results are not filtered: Cross Object Filters do not automatically filter global search results. If you need to filter global search, you must use a different approach, such as a Visualforce page with a custom controller or a custom search component.
Frequently Asked Questions
Can I apply a Cross Object Filter to Reports?
No, Cross Object Filters are not supported on standard Salesforce Reports. They only affect list views and the object’s search functionality. To filter reports, you must use standard report filters and criteria.
What happens if the related record is deleted?
If the related record is deleted, the records on the primary object that were filtered by that relationship will become visible. This is because the filter criteria (the relationship field) is now null or does not exist.
Can I have multiple Cross Object Filters on the same object?
Yes, you can have multiple Cross Object Filters on the same object. However, you must ensure that the filters do not conflict. If a user is assigned two filters with conflicting criteria, the behavior can be unpredictable.
Does a Cross Object Filter work with Record Types?
Yes, you can filter by Record Type. You can use the Cross Object Filter to show only records of a specific Record Type, or you can use it to hide records of a specific Record Type.
Is there a limit to the number of Cross Object Filters I can create?
Yes, there is a limit. The exact limit depends on your Salesforce edition, but generally, there is a limit on the number of Cross Object Filters you can create per org. Contact Salesforce support for the specific limit for your edition.
Can I use Cross Object Filters on custom objects?
Yes, Cross Object Filters can be used on any object, including custom objects. You simply need to ensure that there is a valid relationship between the objects involved.