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
hchhch 

"insufficient access rights on cross-reference id" in lead sharing

Hi,

 

I am getting the above error when I am sharing a lead through apex.

 

Scenario: I am creating a lead by logging in as Partner User. When the assignment rule checkbox is checked the created lead get assigned to another user. I wanted to share that lead with the created user ID(Partner user).  For this purpose, I wrote trigger. When the trigger get fired it is throwing the above exception.

 

How can I resolve it??

 

Thanks in advance!!

 

Navatar_DbSupNavatar_DbSup

Hi,


Please go through the link below may be it helps you on this issue.


https://ap1.salesforce.com/help/doc/en/partner_portal_assign_leads_to_partners.htm

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

hchhch

Hi Navatar,

 

In my case, assignment rule is working fine. After the assignment rule lead is getting assigned to another user. So, the partner user is not getting the  read permission even though he created it. I want to give read access to the partner user.

 

So, I wrote trigger. But the trigger is throwing the exception..

steve456steve456

pls run the debug logs.We can know as to where is the exception being fired

hchhch

I am using the following code..

trigger PartnerLeadSharing on Lead (after insert,after Update) {  

    List<LeadShare> leadsharedelete = new List<leadShare>(); 
    Map<id,User>PartnerUsermap = new Map<id,user>([select id,UserType from user where UserType = 'PowerPartner'] ); 
    SYSTEM.DEBUG('PartnerUsermap----->'+PartnerUsermap);
    List<leadshare> leadshares  = new List<leadshare>();
    leadshare partnershare;
       
    if(Trigger.isInsert){
        if(!PartnerUsermap.isEmpty()){

            for(lead ld : trigger.new){
                if(PartnerUsermap.ContainsKey(ld.createdById)){
                    partnershare = new LeadShare(LeadId=ld.id,UserOrGroupId=ld.CreatedById,leadaccesslevel='read'); 
                    leadshares.add(partnershare);
                  }
            }
            SYSTEM.DEBUG('leadshares----->'+leadshares);

            if(!leadshares.isEmpty()){
               
                Database.SaveResult[] lsr = Database.Insert(leadshares,false);
                SYSTEM.DEBUG('----->'+lsr);
                Integer i=0;

                for(Database.SaveResult sr : lsr){
                if(!sr.isSuccess()){                
    
                    Database.Error err = sr.getErrors()[0];
              
                    if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  
                                               &&  err.getMessage().contains('AccessLevel'))){                 
    
                    trigger.newMap.get(leadshares[i].LeadId).addError(
                       'Unable to grant sharing access due to following exception: '
                       + err.getMessage());
                }
            }
            i++;
            }   
               
        } 
      }
    }

}

 

Vishnu_SFDCVishnu_SFDC
Was there a solution to this?  Please share.  Thanks