function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
j-ferj-fer 

Trigger to update field on Account based on input from Account Team Member

I have go the trigger to update the field on the Account object, but I cannot get the Account record to auto update when I add the data on the Account Team member object.  Please help!

Here is my code.

Trigger
trigger UpdateBankRep on Account (Before update, Before insert)
{
if(checkRecursive.runOnce())
{

Set<Id> accountIds = new Set<Id>();
for (Account acct : Trigger.new)
{
accountIds.add(acct.Id);
}

list<AccountTeamMember> accounts = [Select Id,User.Name from AccountTeamMember where TeamMemberRole = 'Banking Rep' And AccountId IN :accountIds Limit 1];

If(accounts.size() > 0)

{
for(Account acctTeam : Trigger.New )
{
acctTeam.Banking_Rep__c = accounts[0].User.Name;
}
}
Else
{
for(Account acctTeam : Trigger.New )
{
acctTeam.Banking_Rep__c = '';
}
}
}
}

Clase
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
return run;
}
}

Ramu_SFDCRamu_SFDC
Hi as per the description, you are adding the data to account team member however, since the code is written on Accounts object it expects some activity on Accounts object for this code to run and update Account record.