Hi I have written an Apex trigger to add the Opportunity owner name to Account team Member if the opportunity probability is equals to 50%.
However Iam getting errror called Field is not Writeable.
Please find the trigger code and error message below.
trigger addAccountTeam on Opportunity (before insert) {
List<AccountShare> acc_share = new List<AccountShare>();
List<AccountTeamMember> acc_Team = new List<AccountTeamMember>();
for(Opportunity opp: Trigger.New)
{
if(opp.Probability == 50)
{
AccountTeamMember team = new AccountTeamMember();
team.AccountId = opp.AccountId;
team.UserId = opp.OwnerId;
AccountShare share = new AccountShare();
share.AccountId = opp.AccountId;
share.AccountAccessLevel = 'Read/Write';
share.OpportunityAccessLevel = 'Read Only';
share.CaseAccessLevel = 'Read Only';
acc_share.add(share);
acc_Team.add(team);
}
}
if(acc_Team != null)
{
insert acc_Team;
}
if(acc_share != null && acc_share.size()>0)
{
insert acc_share;
}
}
please find the error message