0

I know there has been lot of things available online for record locking errors but I am putting my analysis based on client issue that we are facing, would appreciate if I can get any thoughts.

We have one visual-force page we name it as Survey Program Page and inside that we have table where in user can configure multiple criteria s by adding multiple rows as in say e.g

Row 1 - Account.Name = "xyz"
Row 2 - Account.Email__c = "test@test.com"

We have process builder at backed on Account which has @InvocableMethod which creates custom object record by taking AccountId.

There is also one Trigger on account which do some manipulation on Account record.

As per order of execution Trigger will execute first then Process builder.

Now, User creates Account record with
Account.Name = "xyz" & Account.Email__c = "test@test.com"

First, Account Trigger will be executed and it will do its processing.
Second, Process builder will be executed, @InvocableMethod will create custom object record by taking AccountId

We are receiving error UNABLE TO LOCK ROW when @InvocableMethod tries to create custom object record.

I believe Account Trigger will place lock first on Account Record.

A given transaction can only wait a maximum of 10 seconds for a lock to be released, otherwise it will time out.

I have following questions in my mind

  1. Are we receiving error because Account trigger is taking longer than 10 sec to release lock before it passes Account Record to process builder @InvocableMethod method ?

  2. How does locking work internally ? does each process puts lock and every other process can wait maximum up to 10 sec before previous process release its lock, if its more than 10 sec then next process will throw error as UNABLE TO LOCK ROW or UNABLE TO OBTAIN EXCLUSIVE ACCESS OF THIS RECORD

If this is the case then what would be the ideal approach to deal with this scenario.

  1. Should we work on optimizing code for Account Trigger so that execution time/ locking period will reduce to less than 10 sec.
  2. Is there something that we can do inside process builder so that we can avoid record locking errors.

Thoughts!

  • 2
    As a quick-fix you can go for a scheduled action on the process builder to call the invocable method combined with a execution context variable. As a long term fix you should investigate more on the concurrent records access and try to control the execution chaining – Answers_Seeker Apr 13 '18 at 7:30
  • Thanks for information, it might help me to deal with this scenario, will check around this. – Nachiket Deshpande Apr 13 '18 at 9:25
  • Once the record is locked for update in the Visualforce page, the lock is maintained through the entire transaction, including your triggers, process builder, invocable action, etc. It's likely that the record is locked because someone else is using it at the same time. – sfdcfox Apr 13 '18 at 9:35
  • 3
    No, whatever is going on in the trigger has nothing to do with the process builder/invocable action. The lock applies to the entire transaction. In other words, you have another transaction that's holding up the record. Without seeing all the code, it'd be hard to tell what's going on. You need two separate transactions in order to get this error. – sfdcfox Apr 13 '18 at 9:48
  • 3
    @NachiketDeshpande The Process Builder executes in arbitrary order. Again, the records are locked the entire transaction, so no, you wouldn't get row lock errors because of multiple processes or invocable actions. – sfdcfox Apr 13 '18 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.