I have two objects, pld and lead (relationship is such that lead is a parent and pld is child).

When I'm changing the owner of pld objects then I want to share the lead with new owner of pld object, for which I have created Leadsharing and is updating the same in trigger. But,I'm getting following error:

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

if(Trigger.oldmap.get(pld.id).ownerid != Trigger.newmap.get(pld.id).ownerid) {
    //Owner has changed
    LeadShare ldShare = new LeadShare();
    // Give Read write access to that user for this particular lead record.
    ldShare.LeadAccessLevel = 'edit' ;
    // Assign lead Id of lead record.
    ldShare.leadId = pld.Lead__c;
    // Assign user id to grant read write access to this particular lead record.
    ldShare.UserOrGroupId = pld.ownerid;
    System.debug('pld.ownerid update '+pld.ownerid);
    leadShareList.add( ldShare );
if(!leadShareList.isEmpty()) {
    try {
        upsert leadShareList; 
    } catch(Exception e) {

Related Context: I have created a Leadsharing object for Lead.It contains list of all users to which the lead will be shared.The OWD for Lead is Private.But I'm performing the operation through System Admin.

  • Its difficult to suggest what's going wrong or where to look without looking whole code. List leadShareList has all fields populated? – Raul Oct 16 '17 at 8:29
  • At the beginning of the trigger I'm initializing the list as : list <LeadShare> leadShareList = new List<LeadShare>(); Only this much code is there for updating the leadShareList in trigger. – Pankaj Andhale Oct 16 '17 at 8:34
  • Please check the OWD for both the objects , it looks like there is no share object available for LEAD – user7601 Oct 16 '17 at 9:02
  • Hi Uday, there is a Leadshare object available for Lead,in which the users to which lead is shared are updated.OWD for both object pld and lead is private.But I'm performing the operation through SystemAdmin – Pankaj Andhale Oct 16 '17 at 9:30
  • hi @PankajAndhale, You dont have to update ldShare.leadId as it is already associated correctly. It is just the ownership you must update. Can you try it? – Shalini SF Oct 17 '17 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.