I have a custom object Resource__c having master detail with Account object. I have Account1 created by User1 and if User2 goes to create resource on Account1 then below error is given :"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []".

How can we handle this error before inserting or upserting in our Apex class or do exception handling for this error.

  • 1
    first share your code. Second use try catch to handle exception . Third check Account OWD and profile permisssion. Jan 21, 2016 at 11:54
  • 1
    Can you edit that Account record from UI if you are logged in with User2?
    – Nitin
    Jan 21, 2016 at 11:57
  • @Nitin - I can't edit that record, I agree that I cannot do any operation on that account but as I am having my Create new resource button in layout so I just want to know how to handle this error in my apex class so that error doesn't shown on user or some useful error should be displayed Jan 21, 2016 at 12:33
  • @PraveshMehta I suggest before doing any DMl first check that current user having access to that record or not
    – Ratan Paul
    Jan 21, 2016 at 13:38
  • @Ratan - it would be helpful if you can share some code. If I do such check, then sharing rules will cause any issue or not ? Jan 21, 2016 at 14:02

4 Answers 4


You can 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..

List<UserRecordAccess> lstUserRecordAccess = [SELECT RecordId,MaxAccessLevel,HasAllAccess, 
                                                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.

I hope this will help.

  • 1
    That is related to FLS, but here problem is related to ownership of record. I am not able to modify record whose owner is someone else so I just want to handle error in my apex code. Jan 21, 2016 at 13:36

I ran into this using a dev console script I'd be using w/no issue across all sandboxes for months. The error for me was:

EXCEPTION_THROWN [19]|System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: ...

All my script was doing was creating some new Contact records and associating them w/a specific Account (ID). Oddly after months of working this error popped up (on 2/2/23).

I couldn't find the actual issue/culprit so to resolve I had to delete an Account record and recreate it w/the same info. I realize this solution is messy and likely not feasible for folks struggling w/this issue in a production environment but thought I'd share that in my case, in a sandbox, recreating the record got me past this annoying error.


INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id: [] This error when occurring when we are creating a record with a field relationship master details

enter image description here


You can also check this permissions enter image description here

But In My Case
I did this thing ... We have to allow modify all permission on the parent for example in our case it's User (Custom) Object
enter image description here

  • 4
    You are misreading this documentation. Turning on View All or Modify All is a risky choice. Please do not include your contact information in your SFSE posts.
    – David Reed
    Sep 22, 2020 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .