1.

What Are Sosl Statements In Salesforce Apex?

Answer»

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.

For example, you can return a list of accounts, contacts, opportunities and leds that begin with the phase map.

Note : 

The syntax of the classon 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.

Example:2

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 &GT; ) search list [0] );

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

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

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

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.

For example, you can return a list of accounts, contacts, opportunities and leds that begin with the phase map.

Note : 

The syntax of the classon 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.

Example:2

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]);



Discussion

No Comment Found