Trigger to add Opportunity owner in Opportunity team

Sample Trigger:

trigger OpportunityTrigger on Opportunity (after insert) {
    List<OpportunityTeamMember> listOpptyTeamMem = new List<OpportunityTeamMember>();
    for(Opportunity oppty : trigger.New){
        OpportunityTeamMember OTM = new OpportunityTeamMember();
        OTM.OpportunityId = oppty.Id;
        OTM.TeamMemberRole = 'Sales Rep'; 
        OTM.UserId = oppty.OwnerId;
    if(listOpptyTeamMem.size() > 0){
        insert listOpptyTeamMem;

No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit