I'm getting this error on before insert:
Developer script exception from Organization : Chat_copyUserAgentToNewCase : Chat_copyUserAgentToNewCase: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 500w000001lAWqnAAG; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 500w000001lAWqnAAG: [] Trigger.Chat_copyUserAgentToNewCase: line 14, column 1
Trigger Chat_copyUserAgentToNewCase on LiveChatTranscript (before insert) {
Map<Id, Case> cases = new Map<Id, Case>();
for(LiveChatTranscript trans: Trigger.new) {
if(trans.CaseId != null && trans.UserAgent != null) {
Case c = new Case(Id=trans.CaseId,User_Agent__c=trans.UserAgent);
cases.put(c.Id, c);
}
}
update cases.values();
}
I read this post and the chosen answered suggests to use FOR UPDATE, the problem is that I don't query the cases because I loop over Trigger.New.