0
votes

I am using Salesforce's parameterized search API - https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_search_parameterized.htm - to search my SF instance. However, it sometimes runs quite slow and I want to just the counts to begin with. I see there's a record count API - https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_record_count.htm - but it doesn't accept search terms.

Is there a way to combine these both ? Should I just use the query and use a SOSL query that would just return the counts ? Any pointers on what that SOSL query would look like ?

1
If it's slow, you might want to rethink your approach. One alternative - create these counts via a scheduled job that runs on SF platform, then retrieving them will be fast. - identigral

1 Answers

0
votes

SOSL is not a good choice for counting records matching specific criteria. A SOSL result set maxes out at 2,000 records. Additionally, SOSL results have a latency of up to approximately 15 minutes while indexes are updated, and hence may not be fully up to date at any given time.

Instead, use the Query REST API resource to execute a SOQL query using the filters you're interested in on a single object at a time, using the COUNT() aggregate function in your SELECT clause.

Bear in mind that complex criteria and large data volumes, especially in combination, may cause even a COUNT() query to time out or execute slowly. The fix is situation-specific but likely to involve careful work tuning your query to use indexed fields and efficient comparisons.