Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Friday 27 June 2014

Share a case using trigger

Note:
Default access lavel
trigger trgsharingTest on Case (after insert, after update) {
    if(trigger.isAfter==true && (trigger.isInsert==true||trigger.isUpdate==true) && trigger.new.size()>0 && trigger.new!=null)
    {
      List<CaseShare> lstShare=new List<CaseShare>();
        
        for(Case obj:trigger.new )
        {
           CaseShare objShare=new CaseShare();
              objShare.CaseAccessLevel='Edit';
              objShare.CaseId=obj.id;
              objShare.UserOrGroupId='005i00000038RVcAAM';
              lstShare.add(objShare);
        }
        //Database.SaveResult[] jobShareInsertResult = Database.insert(lstShare,false);
        
        insert lstShare;
    }
}

No comments:

Post a Comment