SOSL
The lib main class for query construction.
Methods
The following are methods for SOSL
.
IN
withDivision(String division)
withHighlight()
withSnippet(Integer targetLength)
withNetworkEqual(Id networkId)
withNetworkIn(Iterable<Id> networkIds)
withPriceBookId(Id priceBookId)
withMetadata(String metadata)
withSpellCorrection()
withoutSpellCorrection()
FIND
Signature
SOSL find(String searchText)
Example
FIND 'MySearch'
IN ALL FIELDS
SOSL.find('MySearch').inAllFields().toSearchList();
IN
inAllFields
Signature
SOSL inAllFields()
Example
FIND 'MySearch'
IN ALL FIELDS
SOSL.find('MySearch').inAllFields().toSearchList();
inNameFields
Signature
SOSL inNameFields()
Example
FIND 'MySearch'
IN NAME FIELDS
SOSL.find('MySearch').inNameFields().toSearchList();
inEmailFields
Signature
SOSL inEmailFields()
Example
FIND 'MySearch'
IN EMAIL FIELDS
SOSL.find('MySearch').inEmailFields().toSearchList();
inPhoneFields
Signature
SOSL inPhoneFields()
Example
FIND 'MySearch'
IN PHONE FIELDS
SOSL.find('MySearch').inPhoneFields().toSearchList();
inSidebarFields
Signature
SOSL inSidebarFields()
Example
FIND 'MySearch'
IN SIDEBAR FIELDS
SOSL.find('MySearch').inSidebarFields().toSearchList();
RETURNING
For more details check RETURNING API.
Signature
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
Example
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.toSearchList();
WITH
withDivision
Signature
ISearchable withDivision(String division);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH DIVISION = 'Global'
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withDivision('Global')
.toSearchList();
withHighlight
ISearchable withHighlight();
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH HIGHTLIGHT
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withHighlight()
.toSearchList();
withSnippet
ISearchable withSnippet(Integer targetLength);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH SNIPPET (target_length=120)
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withSnippet(120)
.toSearchList();
withNetworkEqual
ISearchable withNetworkEqual(Id networkId);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH NETWORK = 'networkdId'
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withNetworkEqual('networkId')
.toSearchList();
withNetworkIn
ISearchable withNetworkIn(Iterable<Id> networkIds);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH NETWORK IN ('networkdId')
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withNetworkIn(new List<Id>{ 'networkId' })
.toSearchList();
withPriceBookId
ISearchable withPriceBookId(Id priceBookId);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH PricebookId = 'pricebookId'
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withPriceBookId('pricebookId')
.toSearchList();
withMetadata
ISearchable withMetadata(String metadata);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH METADATA = 'LABELS'
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withMetadata('LABELS')
.toSearchList();
withSpellCorrection
ISearchable withSpellCorrection();
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH SPELL_CORRECTION
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withSpellCorrection()
.toSearchList();
withoutSpellCorrection
ISearchable withoutSpellCorrection();
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
WITH SPELL_CORRECTION = false
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.withoutSpellCorrection()
.toSearchList();
LIMIT
setLimit
Signature
ISearchable setLimit(Integer amount);
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
LIMIT 100
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.setLimit(100)
.toSearchList();
UPDATE
updateViewStat
Signature
ISearchable updateViewStat();
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
UPDATE VIEWSTAT
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.updateViewStat()
.toSearchList();
updateTracking
Signature
ISearchable updateTracking();
Example
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
UPDATE TRACKING
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.updateTracking()
.toSearchList();
FIELD-LEVEL SECURITY
By default AccessLevel is set as USER_MODE
.
More details you can find in here
systemMode
Execution mode in which the the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords.
Signature
ISearchable systemMode();
Example
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.systemMode()
.toSearchList();
SHARING MODE
Using the with sharing, without sharing, and inherited sharing Keywords
More details you can find in here.
withSharing
Execute query with sharing
.
Note! System mode needs to be enabled by .systemMode()
.
Signature
ISearchable withSharing();
Example
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.systemMode()
.withSharing()
.toSearchList();
withoutSharing
Execute query without sharing
.
Note! System mode needs to be enabled by .systemMode()
.
Signature
ISearchable withoutSharing()
Example
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.systemMode()
.withoutSharing()
.toSearchList();
MOCKING
mockId
TBD
Signature
SOSL mockId(String queryIdentifier)
Example
TBD
list mock
Signature
SOSL setMock(String mockId, List<SObject> records)
Example
TBD
DEBUGGING
preview
Signature
ISearchable preview();
Example
SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.toSearchResult();
SOSL preview will be available in debug logs:
============ SOSL Preview ============
FIND 'MySearch'
IN ALL FIELDS
RETURNING Account
=======================================
RESULT
toSearchList
List<List<SObject>> toSearchList();
Example
List<List<SObject>> searchList = SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.toSearchList();
toSearchResult
Signature
Search.SearchResults toSearchResult();
Example
Search.SearchResults searchResults = SOSL.find('MySearch')
.inAllFields()
.returning(
SOQL.Returning(Account.SObjectType)
)
.toSearchResult();