Searching across a chain of objects in Salesforce

Salesforce users often need to search for data records in one object that depend on conditions in a related object. Frequently, the dependency carries over to multiple related objects, or to chains of such relationships. For example, suppose you need to find all the Campaigns that have targeted the contacts from your Partner accounts. To retrieve those Campaign records, your primary search condition is imposed on the Account object (looking for Partner accounts). Having found those accounts, you must find the Contacts in those accounts, and then the Campaign Member records of those Contacts, and finally the Campaigns to which those member records refer. Thus we have a four-object chain of dependencies that must be traversed to produce the results you need.

Such a query is not very easily constructed in native Salesforce. But Apsona for Salesforce provides the tools you need to solve problems like this. The way Apsona solves the problem is by repeatedly applying the idea of a filter, to produce what is called a nested filter, as follows. A filter is simply a name given to a specific search condition, associated with a specific object. For example, you can create a filter on the Account object, that asks for Account Type matching Partner, and name it Partner Accounts. You can then apply this filter in the Contact object, since the Contact is related to (actually, a child of) the Account object. When doing so, you would retrieve the Contacts of your Partner accounts, and you would use the Partner Accounts filter as a nested filter. You have thus carried a search condition on the Account object over to the related Contact object. You can then repeat this step over the entire chain of objects, thus producing the result you want. See the diagram below, showing the relationships among these objects.

Here is the series of steps to produce your results:

  1. Start with the “primary” object that drives the filter condition. In this case, it is the Account object, since we start with the condition derived from partner accounts. Create a filter on the Account object, identifying your Partner Accounts. You can do this either in the console view (list-and-detail) or in the tabular views in Apsona. Save it with the name “Partner Accounts.”
  2. Create a filter on the Contact object. In doing so, if you open the Account panel of the filter builder, and select the record id field of the Account object, you will see the “in filter” option available. Select that option, and then select the “Partner Accounts” filter. Save this filter with the name “Contacts from Partner Accounts.”
  3. Create a filter on the Campaign Member object, using the Contact filter created in step 2, in the same way.
  4. Finally, create a filter on the Campaign object using the Campaign member filter from step 3.

What we did here was make a filter on the primary object, namely Account, and applied the filter to the related object namely Contact. You can repeat this process as many times as you want, thus carrying filter conditions across a chain of relationships. We use the term nested filter to refer to a filter that uses another filter within it, in this manner.

Searches, filters and reports in Apsona work across the board whether it is retrieve data for campaign management, sales management or case management. Apsona for Salesforce can be downloaded from our AppExchange listing for a 30 day free trial, and works with all editions of Salesforce.

Share Article:

Recent Posts