You need to sign in to do that
Don't have an account?
Vijay Zutshi 2
Multiple Account Member not getting added to Account Team
I have a trigger to create Cutomer Record for the Account Record. When this happens the user in Account Manager field will be automatically added to Account Team of that associated Account. The trigger is just creating 1 team member. So when I want to add another one it does not get added to the Team Member. My trigger is as follows:-
trigger customerAccount on Customer__c (after insert) {
if(Trigger.IsAfter && Trigger.IsInsert) {
SET<ID> customerId = new SET<ID>();
SET<ID> accountManager = new SET<ID>();
LIST<Account> newAccount = new LIST<Account>();
LIST<AccountTeamMember> teamAccount = new LIST<AccountTeamMember>();
MAP<ID, Account> mapIdAccount = new MAP<ID, Account>();
MAP<ID, User> mapIdUser = new MAP<ID, User>();
for(Customer__c newCustomer : Trigger.new) {
customerId.add(newCustomer.Account__c);
accountManager.add(newCustomer.Account_Manager__c);
}
LIST<Account> searchAcc = [SELECT Id, Name
FROM Account
WHERE ID IN :customerId];
for(Account newAccountSearch :searchAcc) {
mapIdAccount.put(newAccountSearch.Id, newAccountSearch);
}
LIST<User> searchUser = [SELECT Id, name,AccountId
FROM User
WHERE Id IN :accountManager];
for(User addUser :searchUser) {
mapIdUser.put(addUser.Id, addUser);
}
//for(Account addTeam :searchAcc) {
//for(User adduser1 :searchUser) {
for(Customer__c addCustomerAcc : Trigger.new) {
if(addCustomerAcc.Account_Manager__c != NULL) {
accountTeamMember team = new accountTeamMember();
team.AccountAccessLevel = 'Edit';
team.AccountId = addCustomerAcc.Account__c;
team.UserId = addCustomerAcc.Account_Manager__c;
team.TeamMemberRole = 'Account Manager';
//team.Id = mapIdUser.get(adduser1.Id).AccountId;
//team.UserId = Trigger.new[0].Id;
//team.AccountId = mapIdUser.get(addteam.Name).Id;
teamAccount.add(team);
}
}
if(teamAccount != NULL && teamAccount.size()>0) {
insert teamAccount;
//team.UserId = mapIdUser.get(addTeam.OwnerId);
//team.AccountId = mapIdUser.get(addTeam.Id).Name;
}
}
}
Please advise where I am going wrong.
Thanks
Vijay Zutshi
trigger customerAccount on Customer__c (after insert) {
if(Trigger.IsAfter && Trigger.IsInsert) {
SET<ID> customerId = new SET<ID>();
SET<ID> accountManager = new SET<ID>();
LIST<Account> newAccount = new LIST<Account>();
LIST<AccountTeamMember> teamAccount = new LIST<AccountTeamMember>();
MAP<ID, Account> mapIdAccount = new MAP<ID, Account>();
MAP<ID, User> mapIdUser = new MAP<ID, User>();
for(Customer__c newCustomer : Trigger.new) {
customerId.add(newCustomer.Account__c);
accountManager.add(newCustomer.Account_Manager__c);
}
LIST<Account> searchAcc = [SELECT Id, Name
FROM Account
WHERE ID IN :customerId];
for(Account newAccountSearch :searchAcc) {
mapIdAccount.put(newAccountSearch.Id, newAccountSearch);
}
LIST<User> searchUser = [SELECT Id, name,AccountId
FROM User
WHERE Id IN :accountManager];
for(User addUser :searchUser) {
mapIdUser.put(addUser.Id, addUser);
}
//for(Account addTeam :searchAcc) {
//for(User adduser1 :searchUser) {
for(Customer__c addCustomerAcc : Trigger.new) {
if(addCustomerAcc.Account_Manager__c != NULL) {
accountTeamMember team = new accountTeamMember();
team.AccountAccessLevel = 'Edit';
team.AccountId = addCustomerAcc.Account__c;
team.UserId = addCustomerAcc.Account_Manager__c;
team.TeamMemberRole = 'Account Manager';
//team.Id = mapIdUser.get(adduser1.Id).AccountId;
//team.UserId = Trigger.new[0].Id;
//team.AccountId = mapIdUser.get(addteam.Name).Id;
teamAccount.add(team);
}
}
if(teamAccount != NULL && teamAccount.size()>0) {
insert teamAccount;
//team.UserId = mapIdUser.get(addTeam.OwnerId);
//team.AccountId = mapIdUser.get(addTeam.Id).Name;
}
}
}
Please advise where I am going wrong.
Thanks
Vijay Zutshi
Can you try adding a account team member manually on the specified account with the same values given in your trigger?
Also, Can you please add a system debug before the line insert teamAccount; to check the how many records are there to insert. I also suggest by trying replicate the same with a simple trigger. may be you can try creating a simple trigger on Account to see if you are able to add multiple accountteammembers
Let me know if it helps