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
JN22JN22 

Trigger Not Firing on Dataload

Hello,

 

My trigger below is designed to update the Account Team object with values from 3 custom fields on the Account object.  The trigger works as expected when I manually change these fields on each Account, however, when I try to bulk load in changes via the dataloader, the trigger does not fire at all.  The custom fields do get populated, but the trigger does not fire.  Can anyone help me figure out why this is not firing?  I also tried to upload only 1 record, but that did not fire the trigger either.  Thanks.

 

trigger AccountTeamChanges on Account(after insert, after update)
{
    //list to hold new account team members
     List<AccountTeamMember> acctMembers = new List<AccountTeamMember>();
     
     //list to hold new account sharing rules
     List<AccountShare> acctSharingRules = new List<AccountShare>();
     
     //misc
     Set<String> rmMemberAccts = new Set<String>();
     Map<ID, ID> AccountTeamMap = new Map<ID, ID>();
    
     //iterate through records to find update processor values
     for(Account a : Trigger.new)
     {

        //new Account - Client Advisor
        if(Trigger.isInsert && a.Client_Advisor__c != null)
        {
            AccountTeamMember ca = new AccountTeamMember();
            ca.AccountId = a.Id;
            ca.TeamMemberRole = 'Client Advisor';
            ca.UserId = a.Client_Advisor__c;
            acctMembers.add(ca);
            
            AccountShare caSharingRule = new AccountShare();
            caSharingRule.AccountId = a.Id;
            caSharingRule.OpportunityAccessLevel = 'Read';
            caSharingRule.CaseAccessLevel = 'Read';
            caSharingRule.AccountAccessLevel = 'Edit';
            caSharingRule.UserOrGroupId = a.Client_Advisor__c;
            acctSharingRules.add(caSharingRule);
        }

        //new Account - Market Director
        if(Trigger.isInsert && a.Market_Director__c != null)
        {
            AccountTeamMember md = new AccountTeamMember();
            md.AccountId = a.Id;
            md.TeamMemberRole = 'Market Director';
            md.UserId = a.Market_Director__c;
            acctMembers.add(md);
            
            AccountShare mdSharingRule = new AccountShare();
            mdSharingRule.AccountId = a.Id;
            mdSharingRule.OpportunityAccessLevel = 'Read';
            mdSharingRule.CaseAccessLevel = 'Read';
            mdSharingRule.AccountAccessLevel = 'Edit';
            mdSharingRule.UserOrGroupId = a.Market_Director__c;
            acctSharingRules.add(mdSharingRule);
        }

        //new Account - Industry Manager
        if(Trigger.isInsert && a.Industry_Manager__c != null)
        {
            AccountTeamMember im = new AccountTeamMember();
            im.AccountId = a.Id;
            im.TeamMemberRole = 'Industry Manager';
            im.UserId = a.Industry_Manager__c;
            acctMembers.add(im);
            
            AccountShare imSharingRule = new AccountShare();
            imSharingRule.AccountId = a.Id;
            imSharingRule.OpportunityAccessLevel = 'Read';
            imSharingRule.CaseAccessLevel = 'Read';
            imSharingRule.AccountAccessLevel = 'Edit';
            imSharingRule.UserOrGroupId = a.Industry_Manager__c;
            acctSharingRules.add(imSharingRule);
        }

        //updated Account
        else if(Trigger.isUpdate)
        {
            //old Accoount record
            Account oldAcct = Trigger.oldMap.get(a.Id);
            
            //check to see if the team values have changed and verifies the
            //new values are not null
            if(oldAcct.Client_Advisor__c != a.Client_Advisor__c && a.Client_Advisor__c != null)
            {
                //add old Client Advisor to remove list if one exists
                if(oldAcct.Client_Advisor__c != null)
                {
                    rmMemberAccts.add(oldAcct.Id);
                    AccountTeamMap.put(oldAcct.Id, oldAcct.Client_Advisor__c);
                }
                
                //add new processor to account team and update sharing rules
                AccountTeamMember ca = new AccountTeamMember();
                ca.AccountId = a.Id;
                ca.TeamMemberRole = 'Client Advisor';
                ca.UserId = a.Client_Advisor__c;
                acctMembers.add(ca);
                
                AccountShare caSharingRule = new AccountShare();
                caSharingRule.AccountId = a.Id;
                caSharingRule.OpportunityAccessLevel = 'Read';
                caSharingRule.CaseAccessLevel = 'Read';
                caSharingRule.AccountAccessLevel = 'Edit';
                caSharingRule.UserOrGroupId = a.Client_Advisor__c;
                acctSharingRules.add(caSharingRule);
            }
            else if(oldAcct.Client_Advisor__c != a.Client_Advisor__c && a.Client_Advisor__c == null)
            {
                rmMemberAccts.add(a.Id);
                AccountTeamMap.put(oldAcct.Id, oldAcct.Client_Advisor__c);
            }

            
            //check to see if the team values have changed and verifies the
            //new values are not null
            if(oldAcct.Market_Director__c != a.Market_Director__c && a.Market_Director__c != null)
            {
                //add old Client Advisor to remove list if one exists
                if(oldAcct.Market_Director__c != null)
                {
                    rmMemberAccts.add(oldAcct.Id);
                    AccountTeamMap.put(oldAcct.Id, oldAcct.Market_Director__c);
                }
                
                //add new processor to account team and update sharing rules
                AccountTeamMember md = new AccountTeamMember();
                md.AccountId = a.Id;
                md.TeamMemberRole = 'Market Director';
                md.UserId = a.Market_Director__c;
                acctMembers.add(md);
                
                AccountShare mdSharingRule = new AccountShare();
                mdSharingRule.AccountId = a.Id;
                mdSharingRule.OpportunityAccessLevel = 'Read';
                mdSharingRule.CaseAccessLevel = 'Read';
                mdSharingRule.AccountAccessLevel = 'Edit';
                mdSharingRule.UserOrGroupId = a.Market_Director__c;
                acctSharingRules.add(mdSharingRule);
            }
            else if(oldAcct.Market_Director__c != a.Market_Director__c && a.Market_Director__c == null)
            {
                rmMemberAccts.add(a.Id);
                AccountTeamMap.put(oldAcct.Id, oldAcct.Market_Director__c);
            }

            
            //check to see if the team values have changed and verifies the
            //new values are not null
            if(oldAcct.Industry_Manager__c != a.Industry_Manager__c && a.Industry_Manager__c != null)
            {
                //add old Client Advisor to remove list if one exists
                if(oldAcct.Industry_Manager__c != null)
                {
                    rmMemberAccts.add(oldAcct.Id);
                    AccountTeamMap.put(oldAcct.Id, oldAcct.Industry_Manager__c);
                }
                
                //add new processor to account team and update sharing rules
                AccountTeamMember im = new AccountTeamMember();
                im.AccountId = a.Id;
                im.TeamMemberRole = 'Industry Manager';
                im.UserId = a.Industry_Manager__c;
                acctMembers.add(im);
                
                AccountShare imSharingRule = new AccountShare();
                imSharingRule.AccountId = a.Id;
                imSharingRule.OpportunityAccessLevel = 'Read';
                imSharingRule.CaseAccessLevel = 'Read';
                imSharingRule.AccountAccessLevel = 'Edit';
                imSharingRule.UserOrGroupId = a.Industry_Manager__c;
                acctSharingRules.add(imSharingRule);
            }
            else if(oldAcct.Industry_Manager__c != a.Industry_Manager__c && a.Industry_Manager__c == null)
            {
                rmMemberAccts.add(a.Id);
                AccountTeamMap.put(oldAcct.Id, oldAcct.Industry_Manager__c);
            }

        }
        
        //DML OPERATIONS
        //remove team members from account team if any exist
        if(rmMemberAccts.size() > 0)
        {
            List<AccountTeamMember> removeTeam = new List<AccountTeamMember>();
            for(AccountTeamMember atm : [SELECT Id, UserId, AccountId
            FROM AccountTeamMember
            WHERE (TeamMemberRole='Client Advisor' OR TeamMemberRole='Market Director' OR TeamMemberRole='Industry Manager') AND AccountId IN :rmMemberAccts])
            {
                if(atm.UserId == AccountTeamMap.get(atm.AccountId))
                    removeTeam.add(atm);
            }
            
            delete removeTeam;
        }
        
        system.debug('-->ACCOUNT MEMBERS: ' + acctMembers);
        //insert the new account team members if any exist
        if(acctMembers.size() > 0)
            upsert acctMembers; //LINE 100
        
        //insert account sharing rules if any exist
        if(acctSharingRules.size() > 0)
            upsert acctSharingRules;
     }
     
}

Ritesh AswaneyRitesh Aswaney

What are you dataloading ? AccountTeams or Accounts ? This trigger is on Accounts so it will fire only if you are datalaoding Accounts.

MVDMVD

the same thing happens for me. It seems the dataloader does not count as an "update" to Dupecatcher. I am also updating Accounts through dataloader, most of which I know are duplicates. If anyone has guidance that would be great! Thanks.