INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id: []


Please use userRecordAccess object to check CRUD permissions.


So pass the recordId and userId to check that user having what type of access on that record.


You can check variables like HasDeleteAccess. If HasDeleteAccess true means user have delete access. If false then user don't have access.


Based on these accessibility perform DML operation 


List<UserRecordAccess> lstUserRecordAccess = [SELECT RecordId,MaxAccessLevel,HasAllAccess, 

                                                     HasDeleteAccess, 

                                                     HasEditAccess,

                                                     HasReadAccess, 

                                                     HasTransferAccess 

                                                FROM UserRecordAccess 

                                               WHERE UserId = '00550000000rlrX' 

                                                 AND RecordId = '0015000000TaWdI'];



You can check accessible rights on any object by describing it as below:


Schema.DescribeSObjectResult accountDescribe = Account.sObjectType.getDescribe();

System.debug('accessible:' + accountDescribe.accessible);


If it is not accessible then, you can show a proper message to user.


 

Comments