• visu visu
  • 0 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0

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,