You need to sign in to do that
Don't have an account?

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
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
Please read this article
http://www.ceus-now.com/why-i-am-getting-field-is-not-writable-opportunityshare-userorgroupid-compile-time-error/