Unlock Record

We’ve updated our component, check out the updated instructions here!

One of the great things about Approval Processes is the ability to lock a record so that a user cannot modify that record. One of the hard things to work around is when a locked record needs to be opened up to be edited again, for instance if, during electronic signature, the customer rejects the signature since they want to negotiate.

Enter the Unlock Record Apex Action, available with Process Builder or Flow! It is as simple as adding in your logic, say the a Quote status is updated to Rejected, then unlock the Quote.

Additionally, you can use this in Flow too. Simply select your Apex Action and add the record Id you’d like to unlock.

And voila, your Quote is unlocked! You can leave it as simple as below, or you can add in logic, like ensuring the Opportunity is not Closed Won, or other things like that!

NOTE: If running Unlock Record Apex Action in Flow, it does respect User permissions. So if a User does not have the permission to Edit a Locked Record, then they will not be able to unlock the record by simply clicking a button that launches to a Flow. Use Process Builder as Process Builder runs in system mode. If the logic is too complex for Process Builder, have Process Builder call the Flow to handle the more complex logic and then it can unlock the record. When Flow is called from Process Builder, it runs in system mode as well.


Leave a Reply to OlyaCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

16 responses to “Unlock Record”
  1. Fred Tchang Avatar
    Fred Tchang

    Hi- this is a great tool, thank you! my users that don’t have the rights to unlock a record, are getting an error even if the Flow is run from Process Builder. Is there something I”m missing?

    The error message I get is: “An Apex error occurred: System.DmlException: Delete failed. First exception on row 0 with id XXXXXXXXXXXXXX; first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []”

    1. Rich Englhard Avatar

      Hi Fred,

      The apex error says Delete failed. This shouldn’t be deleting anything. Are you doing something else in your update? If you launch this from Process Builder, it should unlock no matter what. If you launch it from a button it will not work for someone who does not have the right access, that is until Spring 20, there is an update to allow the flow to run in system mode. I need to test it to confirm, but it should work in that mode for users who don’t have access.

      Rich

  2. Fred Tchang Avatar
    Fred Tchang

    Hi Rich- thanks for your help. You’re right, that is a strange error. It might have nothing to do with this bit of code. I will attempt to isolate the variables in a sandbox and test.

  3. Olya Avatar
    Olya

    Hi Rich,
    I am trying to use the Unlock function to unlock an opportunity that went through an approval process, but it seems to only do it for admins. I built a flow, set it to run in system mode (which you can do as of spring 2020), and created a url button that users can click to unlock their opportunity. However, it only works for admins. I’ve also tried incorporating the unlock action into an auto-launched flow that is triggered by process builder, but that only unlocks for admins too. Process builder simply ignores the unlocking action and moves on to the next record update for non-admins.

    Please let me know if I am missing anything.

    Thanks!
    Olya

    1. Rich Englhard Avatar

      Hi Olya,

      If the record is locked, then out of the box, only those who are allowed to unlock records will be able to use it. It does, however, work with Process Builder in my configurations. So I have had a process unlock a record, for instance if you send out something for signature, you lock the record it sent (like a quote), but then if it is rejected or expired or cancelled, you unlock the record. I have used that with PB. I haven’t tested it in system mode, but will take a look when I get a chance and let you know. I would “think” that should work, but you’ll need to unlock it first before trying to make an update as a user, if that makes sense.

      Rich

  4. Olya Slyusar Avatar
    Olya Slyusar

    Hi Rich,
    Thank you so much for your quick reply! I have the Process builder triggered by a task creation and the PB is supposed to unlock the opportunity and update the stage as well as several fields on the opportunity, then update the task. The strange thing is that when I create the task, PB does everything perfectly (including unlocking the opp); however, when an end user creates a task the PB does everything EXCEPT the opportunity remains locked. So PB is able to update a locked opportunity when triggered by an end user (an end user without the modify all permission) but it’s not able to unlock the said opportunity. I hope that explanation makes sense!

    Thank you again!

    Olya

    1. Rich Englhard Avatar

      It does make sense. I will look into it, most likely this weekend, and if I find anything, let you know.

  5. Jonathan Stringer Avatar

    Hi Rich
    This used to work for non admins for me. Currently when a non admin who has modify all rights on the KB object click the unlock button that triggers the flow to unlock the KB the non admin is now getting the same error below

    : “An Apex error occurred: System.DmlException: Delete failed. First exception on row 0 with id XXXXXXXXXXXXXX; first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []”

    1. Rich Englhard Avatar

      Hi Jonathan,

      The component follows user security, so if they don’t have rights to edit a locked record (modify all), then they wouldn’t be able to use the unlock. We did come out with a new release of Flow Components and in the updated version we do have a capability now for you to allow users who don’t normally have the rights to unlock a record to be able to unlock the record. Please see the following article and let me know if that helps. https://englhardconsulting.com/flow-components-unlock-record/

      Rich

  6. Dave Avatar
    Dave

    Its great to be able to lock and unlock in flow with this but is there also a way to test records before they enter the flow to see if locked or unlocked?

    1. Rich Englhard Avatar

      Hi Dave,

      There is a lightning component, locked record notifier, that you can add to a lightning page that will show a user a notification if the record is locked. There isn’t anything in Flow components that will read that in the Flow itself though.

      Rich

  7. Stefan Avatar
    Stefan

    Hi Rich,
    I need some help with Unlick record.
    After downloading the package, I added a flow and process builder calling the flow. Added permissions sets to user and profile. Nothing worked.

    Stel

    1. Rich Englhard Avatar

      Hi Stel,

      Did you follow the instructions at this link? https://englhardconsulting.com/flow-components-unlock-record/

  8. Bindul Avatar
    Bindul

    Hi Rich,

    I have a record trigger flow that is trying to lock the opportunity product records when the opportunity stage is closed won. I get an apex error.

    Error Occurred:
    An Apex error occurred: System.UnexpectedException: Entity id: XXXXXXXXXXXXXXX cannot be locked.

    Is there a restriction on the opportunity product object?

    Thanks,
    Bindul

    1. Rich Englhard Avatar

      Hi Bindul,

      I’m not sure if you’re allowed to lock that object or not. I would suggest looking into the Salesforce docs for it.

  9. Mark D Avatar
    Mark D

    Hi Rich,

    I have a strange one. We are trying to unlock a Quote when it reaches a certain stage. I have a simple flow which checks that stage as an entry condition. I store the Id into a variable and then pass it to your component.

    When I test it, it works but not all the time. I just tested there times and the first two the record was unlocked and the final one it was not unlocked. I used the same steps and users.

    Can you suggest where I should look?

    Much thanks!
    Mark

Discover more from Englhard Consulting LLC

Subscribe now to keep reading and get access to the full archive.

Continue reading