2

I'm trying to create a trigger that fires and updates the Account/Opportunity Team Members when they are created using the Default Account/Opportunity Teams. However, my trigger does not seem to fire when the default Account/Opportunity Team Members are created using the standard default account/opportunity team functionality. Is there something I'm missing as far as when those records are created?

Trigger:

trigger AccountTeamMemberTrigger on AccountTeamMember (before insert, before update) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        System.debug('Call Helper Class');
        AccountTeamMemberTriggerHelper.updateTeamRole(trigger.new);
    }
}

Helper:

public without sharing class AccountTeamMemberTriggerHelper {
//Method checks the Team Member Role to make sure it's the same as the User Role
//If not it will update the Team Member Role to match the User Role
public static void updateTeamRole(List<AccountTeamMember> accTeamMembers){
    Set<Id> userSet = new Set<Id>();

    for(AccountTeamMember atm: accTeamMembers){
        System.debug('Add User to Set: ' + atm.UserId);
        userSet.add(atm.UserId);
    }

    Map<Id,User> memberMap = new Map<Id,User>([SELECT Id, UserRole.Name FROM User where id IN: userSet]);

    for(AccountTeamMember atm: accTeamMembers){
        if(atm.TeamMemberRole != memberMap.get(atm.UserId).UserRole.Name)
            atm.TeamMemberRole = memberMap.get(atm.UserId).UserRole.Name;
    }
}

}

Thank you, Dan

1
  • Can you add your trigger code.
    – Sarvesh
    Mar 31, 2020 at 16:12

1 Answer 1

2

It's a documented behavior that triggers do not fire when default Account Teams are added in Salesforce Classic.

From Guidelines for Using Account Teams:

Validation Rules and Apex Triggers
In Lightning Experience, when you add account team members or a default account team, validation rules and Apex triggers are applied. In Salesforce Classic, they’re bypassed.

Similar behavior is true of Opportunity Teams:

Default Team Support for Validation Rules and Apex Triggers

Validation rules and Apex triggers are supported when Lightning Experience users add their default team to an opportunity using the Add action on the related list. However, they’re not supported when Lightning Experience users select the personal settings option to add their default team automatically,

Validation rules and Apex triggers aren’t supported when Salesforce Classic users add default opportunity teams via any method.

4
  • The issue I'm running into isn't when the users are adding team members it's when the system is auto creating them via the "Automatically add my default" checkbox. When that checkbox is checked my triggers aren't firing. Also we are in lightning. Mar 31, 2020 at 16:32
  • That may be expected behavior for Opportunity Teams, as above: "However, they’re not supported when Lightning Experience users select the personal settings option to add their default team automatically." Are you seeing it for both types of Team?
    – David Reed
    Mar 31, 2020 at 16:34
  • Yes, I'm seeing this both for Opportunity Teams and Account Teams Mar 31, 2020 at 16:37
  • @DanKowalski did you figure out a workaround? Jun 1, 2022 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .