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
visu visuvisu visu 

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

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
 
Uvais KomathUvais Komath

Please read this article

http://www.ceus-now.com/why-i-am-getting-field-is-not-writable-opportunityshare-userorgroupid-compile-time-error/