+ Start a Discussion
Nandigam RajeshNandigam Rajesh 

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

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. Please suggest me how to do this
Regards
Rajesh
Raj VakatiRaj Vakati
Refer to this link 


https://developer.salesforce.com/forums/ForumsMain?id=9062I000000g6KLQAY

https://github.com/RajagopalAkella/RajRepo2/blob/a8197de3b006b7fdda5d19a9c42e9d3f54ac72c1/src/triggers/OppTeam.trigger​​​​​​​
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 ;
	
}