How to check whether a record has been locked in the Approval Process
12:48 AMHave you been wondering how to check whether a record has been locked? I thought there might be a field which says that. But i was not able to find any such field. Instead i found that ProcessInstance table can be used to find if a record has been locked. But that looks very tedious and complex.
How about a very simple way. Here it is!!
Step1 : Create a field (say FLAG) of type Checkbox. Set the default value to UNCHECKED.
Step2: In your Approval Process in the INITIAL SUBMISSION Action , create a Field Update. Update the FLAG to TRUE.
Step3: In your FINAL APPROVAL and REJECTION Actions, create a Field Update. Update the FLAG back to FALSE.
Step4: And done!!!! You can now find whether a record has been locked simply by checking the FLAG value. Be it in your Apex Class or Visualforce Page.
Comments and queries welcome!!
8 comments
This is great while dealing with a bulk of records...
ReplyDeleteAlso, Views can be created!
Thanks for the Tip
Thats an excellent idea
ReplyDeleteI think in most of the cases orgs have "status" or similar field anyway indicating the stage in approval process, so adding this flag is not necessary.
ReplyDeleteYes cokie.. Usually "Submitted for Approval" status is what many orgs have.. But just in case if there is not any such field then adding this flag maybe helpful rather than querying through the process tables..
ReplyDeleteThe ProcessInstance's "Status = Pending" doesn't necessarily mean that the Record is locked - right??
ReplyDeleteFor example, I have Approved a record. So the ProcessInstance's Status = 'Approved'. But Now, the person next in hierarchy has to Approve it.
So, a record is "unlocked" ONLY when the last person Approves / Rejects - right?
What if a user with Admin priveleges unlocks the record before the Approver has approved :-)
ReplyDelete-Raman
I am having one requirement related to triggers, i.e i want to send approval request beofore deletion reocrd , if approvar approve that then that record should delete other wise it should not be delete. i tried this but it is sending approval request before deleting record, once the approval request is sending , Reocord is also deleting before approval approving this, how can i resolve this.
ReplyDeleteHere that record should stay upto approvar action.
I create one vf page and using username, password. And also I give the my salesforce login credentials through API in my login page. When i click the submit button it will directly go and open the salesforce login page. Please anybody give me related examples.
ReplyDelete