How to check if a record is locked or not in Apex during an approval process

I have an approval process on a Custom object and also two custom buttons on the same record.

Once the record goes into the approval process, it gets locked. During that period, I want to disable/hide the two custom buttons.

How can I check if the record/custom object is locked or not using Apex?

And how can I disable/hide the buttons?


I believe it’s possible to query for the existence of an Approval Request related to your record, I believe this is via: ProcessInstance. Try checking out:

Additionally, you could write a method to attempt to update the record, and trap the exception message that comes from the record being locked and hide the buttons based on that result!

Source : Link , Question Author : Keepcalmncode , Answer Author : JDB

Leave a Comment