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
Luc BlackburnLuc Blackburn 

Row Lock issue on SendEmail ?

I'm using the Messaging.sendEmail function in Apex. How can I get a Row Lock issue from the sendEmail fonction ??

=> First error: SendEmail failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

This is very strange ...
Abhishek BansalAbhishek Bansal
Hi,

ROW_LOCK issue is very common if you have multiple users updating the record at the same time .
Or say a batch job is running and is updating a record and same record another trigger or code snippet (usually a future method) is updating.
Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];
Using FOR UPDATE keyword helps to achieve a lock a client end to prevent this locking issues .

Here is a small article on sharing model to avoid this granular locking

https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US

http://blogs.developerforce.com/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html

Also read on data skews which may be another cause .

Thanks,
Abhishek
Luc BlackburnLuc Blackburn
I'm not trying to update/insert any data. I'm sending an e-mail.

Messaging.sendEmail function
Yaswanth KothapalliYaswanth Kothapalli
Hi Luc,

It' s not an specific error to Messaging.sendEmail function, 

Generally what happens is that when you are sending an email, parallely there is some other action that is performing at the same time on the record which is causing the Lock row.

Log a case with support so that they can check the backend logs based on the time frame that you have received the error so that they can explain you what is causing the issue (I mean what other action is being performed which is causing the lock at the same time) 



 
Luc BlackburnLuc Blackburn
Allright, thanks
Luc BlackburnLuc Blackburn
Apparently i'm not able to do so ... our license doesn't support it ...