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
crop1645crop1645 

OpportunityShare and INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY : SOLVED

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?

 

ANSWER:

 

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) 
crop1645crop1645
post to mark as Solved

All Answers

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

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

Thanks !!!

jungleeejungleee
This really helped. Thanks
Jessica ZurikJessica Zurik
Thanks!
mrferdos mrferdosmrferdos mrferdos
I am always searching online for storys that can accommodate me.www.norton.com/setup There is obviously a multiple to understand about this. I feel you made few salubrious points in Attributes moreover,Office.com/setup
gift cargift car
GreatPeople.me is the news and information source for Associates of the Kroger Co's family of stores. greatpeople.me Kroger Employee Portal is for Kroger Associates/Employees where they can access their account and know Kroger employee benefits. https://krogerfeedback.ninja/how-to-change-greatpeople-me-username-and-password/