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
Wiz76Wiz76 

APEX Sharing Not Working on After Insert But Does After Update

Hi everyone. So I have a requirement to share a private child object (underwriting) to the original opportunity owner. This child record is being created via a button running some javascript from the opportunity page. I have created a trigger that auto-shares it to the designated Sales Rep on each underwriting record. I am attempting to do this after insert, but it is not working. It is working perfectly if I change it to after update though.

 

Can anybody help me figure out why this is happening this way? Sorry if its a simple thing, I'm still a newbie in the APEX coding world.

 

Thanks!

trigger ShareToOppOwner on Underwriting__c (after insert) {


List<Underwriting__Share> UndShare = new List<Underwriting__Share>();

For(underwriting__c und:Trigger.new){
    if(und.sales_rep__c!=null){
        Underwriting__Share us = new Underwriting__Share();
        us.ParentId = und.Id;
        us.UserOrGroupId = und.Sales_Rep__c;
        us.AccessLevel = 'Read';
        UndShare.add(us);
        insert us;
      }  
}
}

 

Wiz76Wiz76

Nevermind. Got it working!

 

Thanks!