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
gauri.gaikwad@fideltech.comgauri.gaikwad@fideltech.com 

UNABLE_TO_LOCK_ROW : unable to obtain exclusive access to this record while updating lead record.

Hi,

when I am trying update lead record or to delete a record i am getting the following error saying "Record Currently Unavailable The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again.
Click here to return to the previous page."

 

I have searched for the problem but has not got any solution for it.

Any other person is not also working on the same lead which i want to delete or update.

I have a trigger on lead which fires after update but it is not updating the lead record, rather it is updating another custom objects record..

Any help would be appreciated..!

Thanks

souvik9086souvik9086

You have update and delete access to lead. right? 

Can you share your trigger here?

gauri.gaikwad@fideltech.comgauri.gaikwad@fideltech.com

Thanks for reply..

i am system administrator so having all the rights over lead object.

Here is the code..

trigger InnovadexLeadTrigger on Lead (before update) {
    Map<ID, Id> leadMap = new Map<ID, Id>();
    for (Lead newLead : Trigger.new) {
        leadMap.put(newLead.Id, newLead.ConvertedContactId);
    }
      
    List <InnovadexRequest__c> innovadexRequests = [select Id, Name, Contact__c from InnovadexRequest__c where Name IN: leadMap.keySet()];
    
    System.debug('lead Id"s=>'+leadMap);
    System.debug('data=>'+innovadexRequests);
    
    for (InnovadexRequest__c innovadexRequest : innovadexRequests) {
        Id contactId = leadMap.get(innovadexRequest.Name);
        innovadexRequest.Contact__c = contactId;
        System.debug('innovadexRequest.Name =>'+innovadexRequest.Name );
        System.debug('innovadexRequest.Contact__c=>'+innovadexRequest.Contact__c);
    }
 
    update innovadexRequests;

}

Ken KoellnerKen Koellner

We get that every once in a while when doing large updates.

 

We put retries in our code.  The update DML is in a try/catch. in a loop.   If  we get the UNABLE TO LOCK row exception, we try again.  We have our loops coded to do just three tries and we always get it to work.

 

Something like the following --

 

	private static final Integer MAX_ATTEMPTS = 3;

	Integer attempts = MAX_ATTEMPTS;
	while(attempts > 0){
		try {
			attempts--; 
			// DO UPDATE DML HERE.
 			attempts = 0;
		} catch (System.DmlException dmlEx) {
        	        if (!dmlEx.getMessage().contains(UNABLE_TO_LOCK_ROW)) { 
                		attempts = 0;  // exit on any other exception
				throw dmlEx;  // throw exception after MAX_ATTEMPTS
			}
	       	} // end of catch
		
	} // end of while retry loop

 

 

 

souvik9086souvik9086

In the first post you wrote

 

"I have a trigger on lead which fires after update but it is not updating the lead record, rather it is updating another custom objects record.."

 

But in the trigger you are not updating lead anywhere, but you are updating the Custom Object "InnovadexRequest__c".

Can you clarify about that?

gauri.gaikwad@fideltech.comgauri.gaikwad@fideltech.com

It means i have a trigger on lead which updates the field 'Contact__c' of custom object namely "InnovadexRequest__c".

The trigger is not updating any field of lead instead it is taking 'convertedContactId' field of lead to update field of custom object "InnovadexRequest__c".

and i am facing the issue since last 2 days and nobody is working on those records.. :(

Having this scenario i am facing the decteted issue.