If you’re unsure of the correct syntax for a SOQL query or a SOSL search, you can get help from the SFRestAPI (QueryBuilder) category methods. These methods build query strings from basic conditions that you specify, and return the formatted string. You can pass the returned string to SFRestAPI or RestClient request methods for query or search.
SFRestAPI (QueryBuilder) provides two static methods each for SOQL queries and SOSL searches: one takes minimal parameters, while the other accepts a full list of options. Swift versions of these methods are not defined explicitly by Mobile SDK. To code these methods in Swift, use the autocomplete suggestions offered by the Xcode compiler. These suggested method and parameter names are determined by Swift compiler heuristics and can differ from their Objective-C equivalents.
The search string. This string can be any arbitrary value. The method escapes any SOSL reserved characters before processing the search.
Swift
Objective-C
fieldScope
fieldScope
Indicates which fields to search. It’s either nil or one of the IN search group expressions: “IN ALL FIELDS”, “IN EMAIL FIELDS”, “IN NAME FIELDS”, “IN PHONE FIELDS”, or “IN SIDEBAR FIELDS”. A nil value defaults to “IN NAME FIELDS”. See Salesforce Object Search Language (SOSL).
Swift
Objective-C
objectScope
objectScope
Specifies the objects to search. Acceptable values are:
nil—No scope restrictions. Searches all searchable objects.
An NSDictionary object pointer—Corresponds to the SOSL RETURNING fieldspec. Each key is an sObject name; each value is a string that contains a field list as well as optional WHERE, ORDER BY, and LIMIT clauses for the key object.
If you use an NSDictionary object, each value must contain at least a field list. For example, to represent the following SOSL statement in a dictionary entry:
1FIND {Widget Smith}2IN Name Fields3RETURNING Widget__c (name Where createddate = THIS_FISCAL_QUARTER)
set the key to “Widget__c” and its value to “name WHERE createddate = “THIS_FISCAL_QUARTER”. For example:
1[SFRestAPI2 SOSLSearchWithSearchTerm:@"all of these will be escaped:~{]"3 objectScope:[NSDictionary4 dictionaryWithObject:@"name WHERE5 createddate="THIS_FISCAL_QUARTER"6 forKey:@"Widget__c"]];
NSNull—No scope specified.
Swift
Objective-C
limit
limit
To limit the number of results returned, set this parameter to the maximum number of results you want to receive.
SOQL Methods
SOQL QueryBuilder methods that construct SOQL strings are:
The sanitizeSOSLSearchTerm method is called in the implementation of the SOSL and SOQL QueryBuilder methods, so you don’t need to call it on strings that you’re passing to those methods. However, you can use it if, for instance, you’re building your own queries manually. SOSL reserved characters include:
\ ? & | ! { } [ ] ( ) ^ ~ * : ” ’ + -
We've Moved
Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.