+ Start a Discussion
visu visuvisu visu 

After Update Trigger on Opportunity for sharing the opportunity record whose stage is CLOSED WON with another USER


I am writing the below after update trigger for sharing an opportunity record whose stage is CLOSED WON to another user in the organization through APEX but I am getting the bellow error. Can any one please help me where and what type of mistake I am doing hear.

Please find the below attached code :

trigger opptrigger on Opportunity (after update)
    list<opportunityshare>opps=new list<opportunityshare>();
    user u=[Select ID From user Where Alias='kuser'];
    for(opportunity op:Trigger.new)
        if(op.StageName=='Closed Won')
          opportunityshare p = new opportunityshare();
            p.opportunityID = op.ID;
            p.UserOrGroupId = u.ID;
            p.opportuniryAccessLevel ='read';
            p.RowCause ='manual';
insert opps;

Error I am getting :
Field is not writeable: OpportunityShare.OpportunityId

Thanks & Regards,
Uvais KomathUvais Komath

Please read this article