• visu visu
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi,

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,
Aj