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
Nandigam RajeshNandigam Rajesh 

need to create oppourtunity team with reference to account team

Hi.
When ever we create or edit an opportunity with an account , then the team members in the account should be created into opportunity team members
How to solve this scenario

Regards
Rajesh
Best Answer chosen by Nandigam Rajesh
Raj VakatiRaj Vakati
You need to use the trigger 

Here is the sample code
 
trigger OpportunityTeamsAuto on Opportunity(after insert){
	
	Map<String,String> oppToAm = new Map<String,String>() ;
	for(Opportunity  o :Trigger.new){
		o.put(o.Id , o.AccountId) ;
	}

	List<AccountTeamMember> teams = [select Id ,AccountId , userid ,TeamMemberRole  from AccountTeamMember where AccountId in :oppToAm.values()];
	Map<Id ,Opportunity> newMapOpp = Trigger.newMap;
	 list<OpportunityTeamMember> oppteam = new list<OpportunityTeamMember>();
	 
	for(AccountTeamMember a :teams){
		Sting oppId = oppToAm.get(a.AccountId);
		OpportunityTeamMember ot = new OpportunityTeamMember();
        //ot.OpportunityId = Trigger.new[0].Id;
        ot.OpportunityId = oppId;
        //ot.UserId = Trigger.new[0].OwnerId;
        ot.UserId = a.OwnerId;
        ot.TeamMemberRole = a.TeamMemberRole;
		            Oppteam.add(ot);

		
	}
	
	insert ot ;
	
}

Refer thislink 

https://github.com/RajagopalAkella/RajRepo2/blob/a8197de3b006b7fdda5d19a9c42e9d3f54ac72c1/src/triggers/OppTeam.trigger

All Answers

Raj VakatiRaj Vakati
You need to use the trigger 

Here is the sample code
 
trigger OpportunityTeamsAuto on Opportunity(after insert){
	
	Map<String,String> oppToAm = new Map<String,String>() ;
	for(Opportunity  o :Trigger.new){
		o.put(o.Id , o.AccountId) ;
	}

	List<AccountTeamMember> teams = [select Id ,AccountId , userid ,TeamMemberRole  from AccountTeamMember where AccountId in :oppToAm.values()];
	Map<Id ,Opportunity> newMapOpp = Trigger.newMap;
	 list<OpportunityTeamMember> oppteam = new list<OpportunityTeamMember>();
	 
	for(AccountTeamMember a :teams){
		Sting oppId = oppToAm.get(a.AccountId);
		OpportunityTeamMember ot = new OpportunityTeamMember();
        //ot.OpportunityId = Trigger.new[0].Id;
        ot.OpportunityId = oppId;
        //ot.UserId = Trigger.new[0].OwnerId;
        ot.UserId = a.OwnerId;
        ot.TeamMemberRole = a.TeamMemberRole;
		            Oppteam.add(ot);

		
	}
	
	insert ot ;
	
}

Refer thislink 

https://github.com/RajagopalAkella/RajRepo2/blob/a8197de3b006b7fdda5d19a9c42e9d3f54ac72c1/src/triggers/OppTeam.trigger
This was selected as the best answer
Nandigam RajeshNandigam Rajesh
Hi Raj,
Thanks a lot for the quick response,
Can you do this task without the customization I.e; via process builder or any other. 
Regards
Rajesh
Raj VakatiRaj Vakati
I dnt think so you can able to copy all accounts team to opportunity teams 

And moreover process builder wnt fire on the Delete