function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion


Problem statement:


When APEX inserting OpportunityShare records, you get DML Exception: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY


Why does this happen?


The obvious reasons are:


  • OpportunityShare.OpportunityId is for an invalid Opportunity (or not an opportunity at all)
  • Running user doesn't have access to the Opportunity in OpportunityId

But if neither of these are the case...what else could it be?




You can not insert OpportunityShare records for the current owner of the record.  You'll need to modify the Apex code to see if the current owner is the same as OpportunityShare.UserOrGroupId.  If it is, then don't insert.  You can still create OpportunityTeamMember records for that user but not OpportunityShare.  Who the current user is will depend if you are doing the OpportunityShare Dml statement in a before trigger, after trigger, VF controller, or API.


Although I haven't tested this, I presume the above applies to AccountShare and CaseShare objects as well.

Best Answer chosen by Admin (Salesforce Developers) 
post to mark as Solved

All Answers

post to mark as Solved
This was selected as the best answer

Came across exactly the same problem and you proactive post saved my day.

Thanks !!!

This really helped. Thanks
Jessica ZurikJessica Zurik
mrferdos mrferdosmrferdos mrferdos
I am always searching online for storys that can accommodate There is obviously a multiple to understand about this. I feel you made few salubrious points in Attributes moreover,
gift cargift car is the news and information source for Associates of the Kroger Co's family of stores. Kroger Employee Portal is for Kroger Associates/Employees where they can access their account and know Kroger employee benefits.