You need to sign in to do that
Don't have an account?

Test Class INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
Having an issue with the below test class. I have an insert trigger for the sharing object upon a field change. When the field next_step = submit then the code grabs a look up to user on the child, and gives the user visibility to the parent.
I keep getting an error:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
Class.TestADRShareSubmitV2.ADRNonApprovalObjectUpdateChildRecordwithSubmit: line 136, column 1
@istest
public class TestADRShareSubmitV2 {
public static testmethod void ADRNonApprovalObjectUpdateChildRecordwithSubmit()
{
//buidling the ADR Master Object
User u =[select id from user where Username = 'bryan.revelant@delmonte.com.saa'];
ADR__c newadr = new ADR__c();
newadr.Review__c ='test account';
newadr.Affiliate_Company__c = 'Test';
newadr.Apex_Status__c = 'Testing Vendor';
newadr.Next_Step__c = '';
newadr.OwnerId = u.id;
insert newadr;
ADR__Share newadrshare3 = new ADR__Share();
newadrshare3.ParentId = newadr.id;
newadrshare3.AccessLevel = 'Edit';
newadrshare3.UserOrGroupId = newadr.OwnerId;
// newadrshare.UserOrGroupId = NEWADRVOU.User__c;
// insert newadrshare3;
//Building the attachement
ADR_Non_Approval_Object__c NEWADRNONAO = new ADR_Non_Approval_Object__c();
//User u =[select id from user where isActive=true limit 1];
NEWADRNONAO.ADR__c = newadr.id;
NEWADRNONAO.User__c = u.id;
NEWADRNONAO.Approval__c = '';
NEWADRNONAO.Approval_Status_Date_Time__c = 'Testing Vendor';
NEWADRNONAO.CheckReadAccess__c = true;
NEWADRNONAO.Comments__c = 'Testing cat';
insert NEWADRNONAO;
ADR_VIew_Only_Users__c NEWADRVOU = new ADR_VIew_Only_Users__c();
User ua =[select id from user where isActive=true limit 1];
NEWADRVOU.User__c = ua.id;
NEWADRVOU.ADR__c = newadr.id;
NEWADRVOU.Status__c = '';
insert NEWADRVOU;
newadr.Next_Step__c = 'Submit';
NEWADRNONAO.Approval__c = 'Submit';
NEWADRVOU.Status__c = 'Submit';
try {
update newadr;
update NEWADRVOU;
update NEWADRNONAO;
} catch (DMLException ex) {
System.assert(true, 'Please Attach The Required Document Below In Notes and Attachment Section.');
}
ADR__Share newadrshare1 = new ADR__Share();
newadrshare1.ParentId = NEWADRNONAO.ADR__c;
newadrshare1.AccessLevel = 'Edit';
//newadrshare.UserOrGroupId = u.id;
newadrshare1.UserOrGroupId = NEWADRVOU.User__c;
insert newadrshare1;
list<ADR__Share> Results = new list<ADR__Share>
([SELECT ParentId, AccessLevel, UserOrGroupId FROM ADR__Share]);
system.assert(Results.size()>0, 'No Answes found: '+ Results);
}
}
I keep getting an error:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
Class.TestADRShareSubmitV2.ADRNonApprovalObjectUpdateChildRecordwithSubmit: line 136, column 1
@istest
public class TestADRShareSubmitV2 {
public static testmethod void ADRNonApprovalObjectUpdateChildRecordwithSubmit()
{
//buidling the ADR Master Object
User u =[select id from user where Username = 'bryan.revelant@delmonte.com.saa'];
ADR__c newadr = new ADR__c();
newadr.Review__c ='test account';
newadr.Affiliate_Company__c = 'Test';
newadr.Apex_Status__c = 'Testing Vendor';
newadr.Next_Step__c = '';
newadr.OwnerId = u.id;
insert newadr;
ADR__Share newadrshare3 = new ADR__Share();
newadrshare3.ParentId = newadr.id;
newadrshare3.AccessLevel = 'Edit';
newadrshare3.UserOrGroupId = newadr.OwnerId;
// newadrshare.UserOrGroupId = NEWADRVOU.User__c;
// insert newadrshare3;
//Building the attachement
ADR_Non_Approval_Object__c NEWADRNONAO = new ADR_Non_Approval_Object__c();
//User u =[select id from user where isActive=true limit 1];
NEWADRNONAO.ADR__c = newadr.id;
NEWADRNONAO.User__c = u.id;
NEWADRNONAO.Approval__c = '';
NEWADRNONAO.Approval_Status_Date_Time__c = 'Testing Vendor';
NEWADRNONAO.CheckReadAccess__c = true;
NEWADRNONAO.Comments__c = 'Testing cat';
insert NEWADRNONAO;
ADR_VIew_Only_Users__c NEWADRVOU = new ADR_VIew_Only_Users__c();
User ua =[select id from user where isActive=true limit 1];
NEWADRVOU.User__c = ua.id;
NEWADRVOU.ADR__c = newadr.id;
NEWADRVOU.Status__c = '';
insert NEWADRVOU;
newadr.Next_Step__c = 'Submit';
NEWADRNONAO.Approval__c = 'Submit';
NEWADRVOU.Status__c = 'Submit';
try {
update newadr;
update NEWADRVOU;
update NEWADRNONAO;
} catch (DMLException ex) {
System.assert(true, 'Please Attach The Required Document Below In Notes and Attachment Section.');
}
ADR__Share newadrshare1 = new ADR__Share();
newadrshare1.ParentId = NEWADRNONAO.ADR__c;
newadrshare1.AccessLevel = 'Edit';
//newadrshare.UserOrGroupId = u.id;
newadrshare1.UserOrGroupId = NEWADRVOU.User__c;
insert newadrshare1;
list<ADR__Share> Results = new list<ADR__Share>
([SELECT ParentId, AccessLevel, UserOrGroupId FROM ADR__Share]);
system.assert(Results.size()>0, 'No Answes found: '+ Results);
}
}
The error is basically coming due to sharing the inserted record back with the owner of the record who has full permissions on it.
If you see while creating the record, the logged in user is the owner as well as Branch Manager of the record. Then in the trigger its again shared back with the Branch Manager who is the owner of the record.
Basically, you cannot restrict the access to the owner of a record.
I will suggest you to create a user and assign it to Branch Manager and then insert it. In the trigger share it with UserInfo.getUserId().
Let me know if you have any questions.
regards,
pardeep.
If it doesnt could you provide a sample of what you are menaing?
Make sure the profile and role can access the object.