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
AA 

APEX sharing between community users?

Hi ,
 Below is the error I'm getting while sharing from one community user to another user

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id.

I was able to see the error in debug log.

Can any one plese help me out here.

Please find below code:

trigger ArticleShare on Article__c (after insert,After update) {
public list<Article__Share> artShareList = new list<Article__Share>();
public list<FeedItem> listOfFeedFiles = new List<FeedItem>();
public attachment objAttachment;
public string usId;
   if(trigger.isAfter){
       if(trigger.isInsert){
           for (article__c a : trigger.new){
               if(a.domain__c!=null || a.domain__c!=''){
               system.debug('__________a.domain__c_______'+a.domain__c);
               for(user u :[select id,name from user where email=:a.domain__c  limit 1]){
                   usId = u.id;
                   system.debug('__________u.id______'+u.id);    
                   //UserOrGroupId  a.Owner.UserRoleId rowCause ='Apex Share' Owner.UserRoleId;
                   system.debug('______a.Owner.UserRoleId_________'+a.Owner.UserRoleId);
                   system.debug('______a.OwnerId________'+a.OwnerId);
                   system.debug('__________u.id______'+u.id);    
                   //system.debug('______u.Owner.UserRoleId______'+u.Owner.UserRoleId);
                   //system.debug('__________u.id______'+u.OwnerId);    
                   Article__Share newartShare = new Article__Share (ParentId  = a.id,UserOrGroupId =u.id,AccessLevel='Read');
                   artShareList.add(newartShare);
                   system.debug('__________artShareList______'+artShareList);    
               }
               
                      
               }
           }
           //insert artShareList ;
           
           
            try {
            Database.SaveResult[] shareInsertResult = Database.insert(artShareList,false);
             for (Database.SaveResult sr : shareInsertResult) {
            if (sr.isSuccess()) {
                
                System.debug('_____Successfully inserted account. Account ID:___ ' + sr.getId());
            }
            else {
                
                for(Database.Error err : sr.getErrors()) {
                    System.debug('_______The following error has occurred___________.'+err.getMessage());                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    
                }
            }
        }

        } 
        catch (Exception e) {
            System.debug(e.getTypeName() + ' - ' + e.getCause() + ': ' + e.getMessage());
        }
           
           
           
       }
   }
   if(trigger.isAfter){
       if(trigger.isUpdate){
           for (Article__c a : trigger.new){
               if(a.domain__c!=null || a.domain__c!=''){
                   
                       for(user u :[select id,name from user where email=:a.domain__c  limit 1]){
                       Article__Share newartShare = new Article__Share (ParentId = a.id,UserOrGroupId =u.id,AccessLevel='Read');
                       artShareList.add(newartShare);
                      
                       
                   }
                   
               }
        
               }
               
               
              //insert artShareList;
              
               try {
            Database.SaveResult[] shareInsertResult = Database.insert(artShareList,false);
             for (Database.SaveResult sr : shareInsertResult) {
            if (sr.isSuccess()) {
                // Operation was successful, so get the ID of the record that was processed
                System.debug('_____Successfully inserted account. Account ID:___ ' + sr.getId());
            }
            else {
                // Operation failed, so get all errors                
                for(Database.Error err : sr.getErrors()) {
                    System.debug('_______The following error has occurred___________.'+err.getMessage());                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    //System.debug(err.getTypeName() + ' - ' + err.getCause() + ': ' + err.getMessage());
                    
                }
            }
        }
        } 
        catch (Exception e) {
            System.debug(e.getTypeName() + ' - ' + e.getCause() + ': ' + e.getMessage());
        }
           }
           
           
          
       }
   

}
AA
Profile of the user who is sharing the recod is "Custome Customer Community Login".It has access tothe Article__C obj.This user sharing to another user who belongs to same profile.

Thanks,
Aravind