+ Start a Discussion
ram_devram_dev 

adding account owner and territory owner to the opportunityTeam

hi,

 

could some one provide the apex code for trigger. that automatically pulls the account owner and territory owner to the sales team.

 

 

 

ram_devram_dev

hi,

 

here is the code i wrote, but got error "invalid field integrity''. Am not sure how come we add at a time account owner and territory owner to the opportunity Team.

 

trigger optyteam Opportunity (After Insert,After Update)
{
    List<id> AccId=new List<Id>();
    List<OpportunityTeamMember> oppMembers=new List<OpportunityTeamMember> ();
    for (Opportunity opp : Trigger.new)
    {   
         OpportunityTeamMember otm=new OpportunityTeamMember ();
         otm.Userid=opp.Accountid;
         otm.opportunityid=opp.id;
         otm.TeamMemberRole='abs';
         oppMembers.add(otm);         
    }
   
    if(oppMembers.size() > 0)
    {  
      insert oppMembers;
    }
}

 

can anyone help me from this.

Avidev9Avidev9

Here is the problem

 

 otm.Userid=opp.Accountid;

 How can you assign AccountId to User Lookup ?

Please assign proper USerId according to your business logic.