+ Start a Discussion
jayamjayam 

Sosl on Triggers

hi

 

Why can't we use SoSL in Triggers.

 Thanks In advance

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Because the apex developer's guide says so:

 

--- snip ---

 

 

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. SOSL queries are only supported in Apex classes and anonymous blocks.You cannot use a SOSL query in a trigger.
--- snip ---
If this is something you want to see, its better to create or promote an idea than post here.

 

All Answers

bob_buzzardbob_buzzard

Because the apex developer's guide says so:

 

--- snip ---

 

 

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. SOSL queries are only supported in Apex classes and anonymous blocks.You cannot use a SOSL query in a trigger.
--- snip ---
If this is something you want to see, its better to create or promote an idea than post here.

 

This was selected as the best answer
Prajapati.LakhanPrajapati.Lakhan

Hi Bob,

 

I am not sure what I am missing but I just tried an SOSL in trigger. It works fine I didnot see any issue.

 

Please confirm if it is because of any salesforce release.

 

Thanks,

Lakhan

bob_buzzardbob_buzzard

The docs still say that you can't use a SOSL query in a trigger - do you get any results when you execute it?  

Prajapati.LakhanPrajapati.Lakhan
Yes and as expected.
bob_buzzardbob_buzzard

I'd raise that as a case with salesforce - sounds like the docs are wrong.

StenEStenE

Did somebody raise a case for this? Are the docs wrong as i can use sosl in triggers as well.

Katia HageKatia Hage

This is an error in the docs. You can use SOSL in triggers.

We will be updating the docs in Winter '13 to remove this incorrect statement. Sorry about that. Btw, this SOSL restriction was enforced in in the past but not any longer since Spring '11.

bob_buzzardbob_buzzard

Thanks for letting us know!