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
dpardpar 

Trigger When opportunityteammember of teamrole is 'Account Manager' update opportunity owner field

Write a trigger to Update the Opportunity Owner field on the Opportunity when a opportunity team member with role “Account manager” is added to the Opportunity. The Account manager will become the Opportunity owner.
NitishNitish
Hi dpar,

Please use below code to solve this problem.
trigger OppTeamTrigger on OpportunityTeamMember (after insert) {
	List<Opportunity> oppList=new List<Opportunity>();
    if(Trigger.isInsert && Trigger.isAfter){
        for(OpportunityTeamMember otm:Trigger.new){
            if(otm.TeamMemberRole == 'Account Manager'){
                
            Opportunity opp=new Opportunity();
            opp.OwnerId = otm.UserId;
            opp.Id=otm.OpportunityId;
            oppList.add(opp);
            }
        }
    }
    if(oppList.size()>0){
        update oppList;
    }
}

Thanks,
Nitish Singh