Salesforce Query usage, limitations and recommendations

This article talks about webMethods support for Salesforce query operation and its limitations.  

 

Usage

 

Query operation executes a query for a selected sObject and returns data that matches the specified criteria. The following predefined parameters are provided:

 

  • select: This parameter contains fields of the selected business object and its related object fields (subquery)/functions. Use this parameter when you want to run a custom complex SOQL query (having subquery, aggregate function, and so on). You can pass any string which is a valid SOQL SELECT clause.
  • where: This parameter can be used to contain a conditional where clause.
  • limit: This parameter can be used to contain the number of records to limit the query.
  • filter: This parameter contains a custom filter condition. If specified, it overrides the where and limit parameters.

 

You can either provide a parameter value at run time or specify a default value in the Parameters tab. The value is given at run time always takes precedence over the default value. However, if the existing default value is of type fixed, overwrite will fail.

 

The response of query operation will always extract the number of records mentioned in the limit parameter, in case if the number of records is more than the limit, Salesforce will respond with queryLocator which is used to extract next set of records. By default, the batch size is defined as 500 by Salesforce and can be increased up to 2,000.

 

Limitations from Salesforce

 

  1. The batch size will be no more than 200 if the SOQL statement selects two or more custom fields of type long text. This is to prevent large SOAP messages from being returned by Salesforce.
  2. QueryLocator expires automatically after 15 minutes of inactivity by Salesforce.
  3. A user can have up to 10 query cursors open at a time. If 10 QueryLocator cursors are open when a client application, logged in as the same user, attempts to open a new one, then the oldest of the 10 cursors is released. If the client application attempts to open the released query cursor, an error “INVALID_QUERY_LOCATOR” occurs.

 

Recommendations

 

  1. If you are running query in a multithreaded environment, make sure you do not generate more than 10 queryLocators unless older queryLocators has been utilized. 
  2. Query using filters to get desired records instead of querying all records which will result in generating multiple queryLocators.
  3. Make sure you use queryLocator within 15 minutes from the time of queryLocator have been generated as queryLocator will be invalidated by Salesforce after 15 minutes.
  4. Use a queryLocator value only once to fetch next set of records.