ads

Friday, 24 March 2017

Apex Sharing In Trigger For multiple Users


Apex Sharing for Standard Case Object . For every Standard Object we need to append Share keyword. Like for case apex sharing object will be CaseShare



Trigger CaseTriggerShraring on Case (After insert){        
        List<CaseShare> csShareList = new List<caseShare>();       
        
        for(Case csInstance:Trigger.New){ 
            
            for(User usrInstance:[Select ID FROM USER WHERE IsActive = TRUE AND ProfileId ='00e5C0000uiuyu']){
                
                CaseShare csShare = new CaseShare();//this should be in for loop
                csShare.CaseId  =csInstance.Id;
                csShare.UserOrGroupId = usrInstance.Id;
                csShare.CaseAccessLevel = 'edit';
                csShareList.add(csShare);
            }
        }
        Insert csShareList;                        
    }

No comments:

Post a Comment