You need to sign in to do that
Don't have an account?
Jemill
I'm having trouble getting my trigger to place a null value in a field when Account Team member is deleted. Old value stays in field on Acocunt
trigger ADAccountTeam on Account (before update, before insert) {
Set<Id> accountIds = new Set<Id>();
for (Account account: Trigger.new) {
accountIds.add(Account.Id);
}
accountIds.remove(null);
Map<Id, Id> accountToTeamMemberMap = new Map<Id, Id>();
for (AccountTeamMember teamMember: [
select UserId, AccountId
from AccountTeamMember
where Account.Id in :accountIds and
TeamMemberRole = 'CJ Advertiser Account Director'
]) {
accountToTeamMemberMap.put(teamMember.AccountId, teamMember.UserId);
}
for (Account account: trigger.new) {
if (accountToTeamMemberMap.containsKey(Account.Id)) {
Account.CJ_Advertiser_Account_Director__c = accountToTeamMemberMap.get(Account.Id);
}
}
}
So this trigger puts the Account Team member into an Account field when the role = CJ Advertiser Account Director. The 2 issues I'm having trouble with is when I delete the Account Team member off, the field on the Account doesn't delete the user from the field when Account is edited. My second question is: Is there a way for this Trigger to execute without someone editing the actual Account? So when the Account Team member is added it would automatically update the Account field.
Set<Id> accountIds = new Set<Id>();
for (Account account: Trigger.new) {
accountIds.add(Account.Id);
}
accountIds.remove(null);
Map<Id, Id> accountToTeamMemberMap = new Map<Id, Id>();
for (AccountTeamMember teamMember: [
select UserId, AccountId
from AccountTeamMember
where Account.Id in :accountIds and
TeamMemberRole = 'CJ Advertiser Account Director'
]) {
accountToTeamMemberMap.put(teamMember.AccountId, teamMember.UserId);
}
for (Account account: trigger.new) {
if (accountToTeamMemberMap.containsKey(Account.Id)) {
Account.CJ_Advertiser_Account_Director__c = accountToTeamMemberMap.get(Account.Id);
}
}
}
So this trigger puts the Account Team member into an Account field when the role = CJ Advertiser Account Director. The 2 issues I'm having trouble with is when I delete the Account Team member off, the field on the Account doesn't delete the user from the field when Account is edited. My second question is: Is there a way for this Trigger to execute without someone editing the actual Account? So when the Account Team member is added it would automatically update the Account field.
All Answers
https://success.salesforce.com/ideaView?id=08730000000YR8IAAW