This error can take place while updating the record manually or using automation. This simply tells the record is locked due to pending approval process or due to being a direct child of a master record. There are two scenario when this takes place.
- When a record is locked due to pending approval process.
- When a record is detail record of a master (child record due to master-detail relationship) and master record is locked.
A lock icon is shown on the record and except admin or approver, no one can update the record.
KNOW RECORD IS LOCKED USING CODE
if you want to know record is locked or not using code then you can use below code:
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
Approval.isLocked(singlerecordId); or Approval.isLocked(List<Id> recordIds);
MANAGE IT USING CODE
Unlock the record as below:
Approval.unlock(singlerecordId); OR Approval.unlock(List<Id> recordIds);
Lock the record as below:
Approval.lock(singlerecordId); OR Approval.lock(List<Id> recordIds);