function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chris_centrachris_centra 

context across transactions?

Hello.  i have class which performs round-robin assignment of records.  until recently, i was able to control the calls to this code - so i knew there would never be more than one record processed at a time.  but now we had to build a web service interface on it - and the calling system can make two calls concurrently - which can cause a conflict with the round robin setup (the code will assign the same owner to both records, then they both try to update the RoundRobin config record - and one of those updates fails).  

 

question is - what are the best approaches to sharing context across concurrent transactions?  as far as i know there's no way to communicate directly between transactions.  could use the db but i don't really want to add a handful of db reads/writes for each transaction.  maybe a custom setting that i maniuplate from the code - but i'm not that's any faster than the db.  what else?

 

thanks for your time.

chris

Best Answer chosen by chris_centra
digamber.prasaddigamber.prasad

Hi,

 

You are right that there is no out of the  box way in salesforce to communicate directly between transactions. Which leave only available option of use object or custom settings. Both of these are indeed same. You can lock statement using http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm .

 

Let me know if you have any specific question.

All Answers

digamber.prasaddigamber.prasad

Hi,

 

You are right that there is no out of the  box way in salesforce to communicate directly between transactions. Which leave only available option of use object or custom settings. Both of these are indeed same. You can lock statement using http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm .

 

Let me know if you have any specific question.

This was selected as the best answer
chris_centrachris_centra

Interesting - i confess i was not aware of the "FOR UPDATE" option in SOQL.  is there any way i can use that information to help me though?  for example, is it possible for me to only query records that aren't currently locked?  or is it possible for me to know that a record is locked without attempting to update it?  that would be my solution, i think.

thanks again for your time.

chris