+1 vote
in Salesforce by
SOSL Statements In Salesforce Apex?

1 Answer

0 votes
by
SOSL statement evaluate to a list 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 query.

If a SOSL query does not return any records for a specified sObject type, the search results include an empty list for that sObject.

Example: You can return a list of accounts, contacts, opportunities and leads that begin with the phase map.

1

List < list < subject >> search list = [ find 'map*' In ALL FIELDS RETURNING Account (ID, Name), contact, opportunity, lead ];

Note:

The syntax of the class on Apex differs from the syntax of the FIND clause in the SOAP API.

In Apex, the value of the FIND cause is demarcated with single quotes.

Example:1

FIND 'map*' IN ALL FIELDS RETURNING account (Id, Name], Contact, Opportunity, Lead. In the Force.com API, the value of the FIND Clause is demarcated with braces.

FIND {map*} IN ALL FIELDS RETURNING account  [Id,name], contact ,opportunity,lead;

From search list , you can create arrays for each object returned.

Account [ ]  accounts = (( list < accounts > ) search list [0] );

Contact [ ]  contacts = [( list ) search list [0]) ;

Opportunity [ ] opportunities = ((list < opportunity> ) search list [2]) ;

Lead [ ] leads = (( list < lead> ) search list [3]);

Related questions

+1 vote
asked Sep 24, 2019 in Salesforce by Robin
+1 vote
asked Sep 24, 2019 in Salesforce by Robin
...