Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
SOQL and SOSL Queries
SOQL Statements
SOQL statements evaluate to a list of sObjects, a single sObject, or an Integer for count method queries.
1List<Account> aa = [SELECT Id, Name FROM Account WHERE Name = 'Acme' WITH USER_MODE];1if (!aa.isEmpty()) {
2 // Execute commands
3}1Contact c = new Contact(Account = [SELECT Name FROM Account
2 WHERE NumberOfEmployees > 10 WITH USER_MODE LIMIT 1]);
3c.FirstName = 'James';
4c.LastName = 'Yoyce';1Integer i = [SELECT COUNT() FROM Contact WHERE LastName = 'Weissman' WITH USER_MODE];1Integer j = 5 * [SELECT COUNT() FROM Account WITH USER_MODE];SOQL limits apply when executing SOQL queries. See Execution Governors and Limits.
For a full description of SOQL query syntax, see the Salesforce SOQL and SOSL Reference Guide.
SOSL Statements
SOSL statements evaluate to a list of lists of sObjects, where each list contains the search results for a particular sObject type. The result lists are always returned in the same order as they were specified in the SOSL query. If a SOSL query doesn’t return any records for a specified sObject type, the search results include an empty list for that sObject.
1List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead WITH USER_MODE];- In Apex, the value of the FIND
clause is demarcated with single quotes. For
example:
1FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, LeadApex that is running in system mode ignores field-level security while scanning for a match using IN ALL FIELDS.
- In the API, the value of the FIND
clause is demarcated with braces. For
example:
1FIND {map*} IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead
1Account [] accounts = ((List<Account>)searchList[0]);
2Contact [] contacts = ((List<Contact>)searchList[1]);
3Opportunity [] opportunities = ((List<Opportunity>)searchList[2]);
4Lead [] leads = ((List<Lead>)searchList[3]);SOSL limits apply when executing SOSL queries. See Execution Governors and Limits.
For a full description of SOSL query syntax, see the Salesforce SOQL and SOSL Reference Guide.