I'm trying to re-factor a trigger because it is operating on a Contact Record type that contains more than 100,000 objects. I easily switched over to the SOSL equivilant, but now my code is behaving as if the records I insert are not being inserted. This works perfectly when I use SOQL, but the records are to great and it is no longer an option. Also, I cannot set NPSP fields to be External IDs since it is a managed external package :P Here's some psuedo code to try and clarify:

>>Trigger is started from an 'Order'
>>Contact email is checked to see if a contact already exists for that email
List<Contact> Contacts = [FIND :EmailSearchString IN EMAIL FIELDS RETURNING Contact(Id,npe01__HomeEmail__c )];

>>Check if contact exists already, update if it does >>exit routine
>>if not create a new Contact based on order information
>>Update original 'Order' with the newly created Contact ID

The way the trigger is setup, since I am updating the original triggered Order it runs twice, but dumps out of the routine since the Contact is matched. This prevents it from infinitely looping. Using SOSL, the newly created Contact doesn't appear in the SOSL query the second time it runs, and i hit a 'Too many DML statements' error. The stranger part is that I can verify that the new contacts are inserted via Database.Insert and checking the results. It just seems like the SOSL query doesn't find the Contacts the second time the trigger runs(where as SOQL does).

Does SOSL employ some sort of timed caching so it isn't seeing my newly created records instantly, or am I grossly overthinking this problem?

1 Answer 1


SOSL is indexed asynchronously. You can't rely on the results being available in real-time, or even within a few seconds after the final commit. Use SOQL if you need potentially real-time results.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .