You need to sign in to do that
Don't have an account?
Andrew Likens 6
create opportunity team member with user id as trigger.new opportunity team member managerId
I have started to try to build this out using process builder and using an invocable method. My work saves, but it is not executing the way I want. Any ideas are greatly appreciated! Code below.
public class OBLOppTeamMembers { @InvocableMethod public static void createOBLOppTeamMemberManager(List<OpportunityTeamMember> otmToUpdate) { List<OpportunityTeamMember> otm = [SELECT Id, UserId, OpportunityId, TeamMemberRole,OpportunityAccessLevel FROM OpportunityTeamMember WHERE Id IN :new Map<Id, OpportunityTeamMember>(otmToUpdate).keySet()]; Set<Id> userIds = new Set<Id>(); for(OpportunityTeamMember oppTM : otm) { userIds.add(oppTM.UserId); } List<User> userList = [SELECT Id, ManagerId FROM User WHERE Id IN :userIds]; Map<Id, User> userById = new Map<Id, User>(); for(User u : userList) { userById.put(u.ManagerId, u); } for(Id managerId : userById.keySet()) { for(OpportunityTeamMember oppTM : otm) { OpportunityTeamMember newOppTM = new OpportunityTeamMember(); newOppTM.UserId = managerId; newOppTM.OpportunityAccessLevel = 'Edit'; newOppTM.OpportunityId = oppTM.OpportunityId; newOppTM.TeamMemberRole = 'Regional Manager'; } } update otm; } }
At line 25, you are creating records for OpportunityTeamMember but you are not making INSERT DML on these newly created ones.
Try this code:
In your code, what you were doing wrong was:
You are updating the old list 'otm'.
You need to add the new records which you are creating with updated field values in a list and then update that list.
Let me know if it helps.
thanks