You need to sign in to do that
Don't have an account?
ENTITY_IS_LOCKED, the entity is locked for editing: [] -- Insert Failed
Hi,
We have implemented one solution using Master Detail Relationship. While submitting Master Record for an approval, we create it's detail records. It's functionality is working fine as per requirement but while writing its test classes, we are getting "ENTITY_IS_LOCKED, the entity is locked for editing: [] -- Insert Failed".
We are running test method using business user who actually creates master record & its detail records gets automatically created as per business logic.
As I understand, Master record gets automatically locked when submitted for an approval & hence detail object also gets locked (Controlled by Parent sharing setting). That's why while creating record for detail object, we are getting "ENTITY_IS_LOCKED, the entity is locked for editing: [] -- Insert Failed".
Also, Why am I not getting this error while testing actual implementation ??
Kindly let me know how can we fix this test class issues.
Thanks.
Michael Dsoza
We have implemented one solution using Master Detail Relationship. While submitting Master Record for an approval, we create it's detail records. It's functionality is working fine as per requirement but while writing its test classes, we are getting "ENTITY_IS_LOCKED, the entity is locked for editing: [] -- Insert Failed".
We are running test method using business user who actually creates master record & its detail records gets automatically created as per business logic.
As I understand, Master record gets automatically locked when submitted for an approval & hence detail object also gets locked (Controlled by Parent sharing setting). That's why while creating record for detail object, we are getting "ENTITY_IS_LOCKED, the entity is locked for editing: [] -- Insert Failed".
Also, Why am I not getting this error while testing actual implementation ??
Kindly let me know how can we fix this test class issues.
Thanks.
Michael Dsoza
Hi Michael,
Don't know why you are not getting this in actual implementation. If i get this kind of problem, i will just use Test.isRunningTest().
You can put Test.isRunningTest() this condition before sending for approval.
if(!Test.isRunningTest()) {
//send for approval
}
Thnaks,
Manohar
I can not use of Test.isRunningTest to avoid set of lines because I need child object reords for further processing.
Is their any way to UNLOCK ENTITIY State ??
Thanks
Michael Dsoza
Hi Michael, you can try Approval.lock(rec, false), Approval.unlock(rec, false).
rec is the list of record you want to lock or unlock. Hope that will help.
Thanks,
Manohar