How do I check if a record of a custom object is locked through an approval process ? I know i can use the ProcessInstance to access my approval processes, but I can't check if it is locked or unlocked.

  • did you look at this - salesforce.stackexchange.com/questions/30977/… ? – cropredy Apr 28 '14 at 14:33
  • Yes, but I really don't like that "solution". If I want it that way, I could just check the ProcessInstance, but that have nothing to to with the actual record lock. – David Renz Apr 28 '14 at 14:40
  • I was thinking more about the response I made on that post (see crop1645; use a custom field) - this is how I check for locked records – cropredy Apr 28 '14 at 16:16
  • Did you check salesforce.stackexchange.com/questions/1298/…? – Robert Sösemann Apr 29 '14 at 7:13
  • @crop1645 After my final final accept/reject/recall the record is still locked, that's why with solution doesn't work for me. I have to check the actual lock of the record. This lock is nearly independent from the approval process. – David Renz May 5 '14 at 8:59

You could create an "In Approval Process?" checkbox and set it to true in the Initial Submission Actions and then set it to false in the Final Approval, Rejection, and Recall Actions of approval processes.

SF has added isLocked method in System.Approval class from Spring 16 (Api level 36). So it is now possible to check if the record is locked or unlocked using Apex.

Additionally, SF has also added the ability to lock/unlock the record using Apex code. Please refer to same document. Basically, the code would look like


Check https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_methods_system_approval.htm#apex_System_approval_isLocked for more info

  • 1
    This is a simple click-based answer that doesn't require code. – Mike Chale Apr 28 '14 at 18:54
  • If a record is approved, it should be still locked and it is still locked. Is there no possibility to check this lock ? – David Renz Apr 29 '14 at 6:49
  • 3
    Unfortunately, David, there is no possibility to check via Apex whether or not a record is locked. – Rob Alexander May 5 '14 at 20:21

Another workaround is to activate 'Track Field History' for the custom object, then if the record is locked it will be shown in the custom object History table.

For example if you have a custom object "Project" with API Name "Project__c", if you activate 'Track Field History' the table "Project__History" will be automatically created and you can check if a record is locked using this query:

SELECT CreatedDate, CreatedById, Field, ParentId FROM Project__History WHERE ParentId='a0P370000005PkHEAU' ORDER BY CreatedDate DESC LIMIT 1

(with the ParentId value in the WHERE clause the Id of the Custom Object Record.)

and checking that Field is equal to locked:

Project__History  p = [SELECT CreatedDate, CreatedById, Field, ParentId FROM Project__History WHERE ParentId='a0P370000005PkHEAU' ORDER BY CreatedDate DESC LIMIT 1];
if (p.Field == 'locked') {   //the record is locked }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.