Questions tagged [locking]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
42
votes
4answers
13k views

SOQL Record Locking : For Update

Well I was trying to Implement Record Locking apex but Salesforce Document doesn't seem to help much. Even tried searching stackexchange there was a old question but the answer form StackExchange and ...
38
votes
1answer
604 views

Help me solve a concurrency mystery (platform bug? Expected behavior? Or am I missing something?)

To set up the problem, add a new currency data type custom field called Test_Counter__c to the Opportunity Object. Then create a test opportunity named TestOp. Then create the following class: ...
22
votes
2answers
1k views

Is it possible to simulate record locks in test methods?

I would like my test cases to also test exception handling. In theory an easy way to cause an exception on DML is to lock a record that it'll update so that the update will fail. But I'm having ...
11
votes
1answer
2k views

When is a FOR UPDATE lock released?

The Salesforce docs say that The lock gets released when the transaction completes Does that mean when the record is updated, or when the execution context completes?
11
votes
2answers
5k views

Salesforce Parent Locking 'UNABLE TO LOCK ROW'

Does salesforce lock Account Record when user try to update/create following child objects - AccountTeamMember Opportunity Line Item (Does sfdc lock opportunity here as well?) Task Contact ...
10
votes
1answer
365 views

do methods execute atomically?

Do apex methods execute atomically? Is this method acceptable as-is or could multiple users cause a race condition? public static Integer transactionID(){ TradeCount__c t=[SELECT ...
10
votes
1answer
144 views

FOR UPDATE returns old values

I use FOR UPDATE locking in a query but when the first execution completed, the second execution (started while records were locked) seems to use the old data set. I played around for a while and ...
9
votes
1answer
2k views

Reproduce UNABLE_TO_LOCK_ROW error

We're receiving the: caused by: System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] exception in ...
8
votes
2answers
1k views

The cause of UNABLE_TO_LOCK_ROW error?

My scenario is as followed, I have a single Parent account with about 600 child accounts. Every child account has a single Opportunity with 2 or more lines. I have a monthly batch job to create ...
8
votes
1answer
142 views

Will a DML ever lock a “grandparent” record?

Let's say I have two levels of master-detail relationships. Grandparent object is master-detail to Parent obj, which is in turn master-detail to Child object. I have an existing Granparent record G1....
7
votes
4answers
3k views

I want to lock the record using apex

I am inserting the record using apex and visual force page. I want to lock the record when i click submit on the visualforce page.i.e when i open the record in salesforce I don't want the records to ...
7
votes
2answers
2k views

Can a DML retry solve UNABLE_TO_LOCK_ROW race conditions?

I have 2 Batch classes working on different child objects of a common master object. Batch Batches are started parallel to speed up this long running cleansing operation. It depends on the underlying ...
6
votes
1answer
8k views

Approval lock/unlock with APEX

I am in Winter '16 and trying to unlock and lock a record in APEX and I am getting the following exception FATAL_ERROR System.UnexpectedException: Apex approval lock/unlock api preference not ...
6
votes
1answer
292 views

GroupMember locking

For out project we need to put users into correct public groups. This happens in a trigger when a user's contact is updated, depending on some of the fields there we decided where to put a user. The ...
6
votes
1answer
84 views

Apex Approval.lock, programmatic locking and record editability

Background: In Winter '16, Salesforce introduced the Approval class for setting approval locks and unlocks through Apex (release notes). Since then, my company has been leveraging this functionality ...
6
votes
1answer
316 views

Users getting “Unable to obtain exclusive access” Error

My users are attempting to work in records and occasionally get the error message of Unable to obtain exclusive access to this record or 1 records: [id]. This error is intermittent and I cannot find ...
5
votes
2answers
970 views

Disable Parallel Test vs. Always Run Asynchronously in Dev Console - Who wins?

I love to run my tests in the Dev Console with the Always Run Asynchronously checkbox enabled as it saves time. On the other side during our automated Nightly Test run I would like to disable ...
5
votes
2answers
145 views

Pessimistic Lock Released after Callout

The documentation says: The lock gets released when the transaction completes. However I can validate that it also gets released when a callout is made! Here a two test methods: public static ...
5
votes
1answer
162 views

Bulk API Row Lock Root

How to get confirmation that Inserts/Deletes of Contacts using the Bulk API will cause Row Lock errors on the parent Accounts, especially if the # of Contacts is large and there are few parent ...
4
votes
2answers
1k views

Can one implement a Mutex / Lock / Semaphore in Salesforce?

I have multiple processes (teams of users) that need to mutually exlusive work on the sames data records in Salesforce. Is there a way to simulate a kind of Mutex or Semaphore in Salesfore (e.g. ...
4
votes
2answers
77 views

Spin locks with variable time retry backoffs

Use Case After insert triggers start Queueable Queueable execute() contends for same resource, uses spin lock to wait for resource availability. Many queueables could be running at same time. ...
4
votes
1answer
336 views

Optimistic locking when working via REST API

I have a case when SF data can be updated concurrently by humans with UI and by a Ruby app via REST API, so I'm worried about the possibility they overwrite changes of each other. Is there a standard ...
4
votes
1answer
401 views

SObject type does not allow locking rows

I am trying to update a group of records satisfying certain conditions it was giving me Error which says:- UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 10 records so ...
4
votes
1answer
81 views

Avoid new record race conditions with FOR UPDATE [closed]

Under simple circumstances FOR UPDATE does only respect records that existed when the query was executed. But I need all available records matching my query when the transaction proceeds. Let me ...
3
votes
1answer
311 views

Bulk API Error: UNABLE_TO_LOCK_ROW:unable to obtain exclusive access to this record or 124 records

During the process of loading 90,000 opportunities into Salesforce using the Bulk API, I get this error: UNABLE_TO_LOCK_ROW:unable to obtain exclusive access to this record or 124 records... After ...
3
votes
1answer
1k views

UNABLE_TO_LOCK_ROW Error with Test Class [duplicate]

When running all test classes from the Setup menu in a Sandbox org at the same time, I am receiving the error "System.DmlException: Insert failed. First exception on row 0; first error: ...
3
votes
3answers
2k views

Edit Fields in Closed Opportunity

I've given a Profile read/write access over several fields on the Opportunity level. However, because the record is locked after Closing Lost or Won, they cannot edit the fields. How can I choose to ...
3
votes
2answers
892 views

Implicit sharing & Record locking

I am trying to understand if Implicit sharing capability can be used to avoid record locks or increasing performance of update operations on master-detail records. I am referring to this link here. ...
3
votes
1answer
7k views

UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record

I have a batch process which updates Accounts and sometimes when i run this batch i get the error. UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record I did read through Mohit's ...
3
votes
1answer
47 views

Does the FOR UPDATE field apply to reference fields?

If do a query like [SELECT Opportunity.Name, Product2.Name FROM OpportunityLineItem FOR UPDATE], is the Opportunity and Product2 locked, or just the OpportunityLineItem? I'm trying to set a field on ...
3
votes
1answer
124 views

allOrNone flag does not work when at least one record is locked

I am trying to create a reusable method which retries DML whenever record lock is detected. However, I noticed that even if you set database.update( collection, **false**) and there is at least one ...
3
votes
1answer
979 views

What actions would cause a record to be locked?

Yesterday, some Users experienced an error when attempting to change the Owner on open Cases using the Salesforce interface. This issue lasted for about an hour. Afterwards, updating the Owner on ...
3
votes
0answers
69 views

Resolving UNABLE_TO_LOCK_ROW issue

Is there any way to identify which transaction/class took the lock the record when we get this UNABLE_TO_LOCK_ROW issue. Simply giving UNABLE_TO_LOCK error and not giving the idea about he potential ...
2
votes
2answers
623 views

Is it possible to use Apex Scheduler to run a batch class just once, 30 seconds after the scheduler is called?

I want to call a Schedulable class from within a trigger, to execute a batch job after waiting 30 seconds (or 5 seconds, as long as it's long enough to make absolutely sure the initial trigger ...
2
votes
1answer
707 views

Would updating children records at the same time cause “UNABLE_TO_LOCK_ROW” error? How can I avoid this?

I have 3 objects with the below relationship: One Account(Master) Opportunity(Detail) Custom__c(Parent) (lookup on opportunity) Opportunity(Child) Here's the scenario: I have 1 ...
2
votes
2answers
628 views

Lock Idea record on field update

I need a way to lock an Idea and its comments from being editable. I have a time-based workflow already set up to change a custom field after 30 days. The custom field is called voting status with ...
2
votes
0answers
189 views

Group membership locks - Territory Hierarchy updates & Sharing recalculations

I read through the Record Locking Cheat Sheet to understand record locking concepts and have some follow-up questions: What can be the cause of Group membership locks with relevance to Territory ...
2
votes
0answers
296 views

Checking Object Lock status using REST API

We are running into the object lock contention UNABLE_TO_LOCK_ROW error when attempting to create a record in the CampaignMember object using AMPscript in Marketing Cloud due to the high lock ...
2
votes
0answers
844 views

CreateSalesforceObject AMPscript function and Record Locking Concurrency

We are using the CreateSalesforceObject AMPscript function to create a new record in the Salesforce CampaignMember Object when an email is sent, by including the following code in an email: set @...
2
votes
0answers
102 views

Unlock parent, then update child, then again lock back the parent

I have a batch class that is used to update a Field1 of Obj1. Obj1 is child of Obj11. Inorder to update Obj1, I need to unlock its parent Obj11 first. [by updating lock__c=false]. Then update ...
2
votes
0answers
125 views

Salesforce Optimistic Record Locking and JavaScript Updates

Is there a way to implement field only updates for Salesforce? Even if fields could be updated concurrently through JavaScript/JavaScript remoting calls, would Salesforce still save the record using ...
1
vote
2answers
48 views

User hits record lock error despite class without sharing

My users keep hitting a record lock error despite the class being defined as without sharing. My understanding is that without sharing allows locked records to be edited by any user. This class is the ...
1
vote
2answers
227 views

Salesforce Bulk API Unable to lock row

I'm currently using the Salesforce Bulk API within a Rails app to update a custom object in Salesforce. This works fine when I send a single record through, but when I batch in sets of 200, I get ...
1
vote
2answers
3k views

Why can't I lock/unlock records through apex?

In my attempts to use the Approval class methods to unlock locked records or to lock unlocked records, I have encountered the following warning: System.UnexpectedException: null I saw this error ...
1
vote
1answer
320 views

Waiting for a record to be unlocked in Apex

As You know how we can lock records in Apex by adding a FOR UPDATE at the end of SOQL query. In one of my classes I have to query for a bunch of records and then updating them. In this query I use ...
1
vote
1answer
451 views

Can a future method conflict with a queuable method?

My custom code is executed using a queuable class. Sometime it runs perfectly, other times it gives this error: Failed to update list. Error: System.DmlException: Update failed. First exception ...
1
vote
2answers
3k views

Locking the fields and buttons when a certain condition is met

I have situation here, where I want to lock all the fields and buttons on a quote__c (custom object) where the status of the quote is changed to 'Sent' so that nothing can be editable on the quote. ...
1
vote
1answer
80 views

Apex Approval Process Locks on DML Statements

I have a custom button on a record which is designed to update the record's status. There is a separate process within a different class, which is locking the record. I need my pageRef to unlock the ...
1
vote
1answer
52 views

Is it possible to have a validation rule with a finely nuanced loophole to create and modify detail records?

We have Opportunity with a custom checkbox property "Locked__c". While this value is set to true (never mind how), it should be impossible to change any value on the Opportunity. The Opportunity has ...
1
vote
1answer
805 views

Lock a checkbox based on another field

I have a picklist on my object called Type: New / Pending / Historical when the Type field is set to: New, then I would like to prevent another picklist field from being edited. This field is called:...