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
babrannobabranno 

Bulkify Helper Class and Trigger Help Needed

I am desperate for some help.  I have a trigger and help class for the Task object.  It was originally written by our implementer but it appears that he failed to bulkify the trigger and helper class.  I have been trying to hack my way through fixing this with no luck and my company won't give me the money to hire someone to fix it.  I would appreciate any help I could get. 

 

This trigger and helper class is preventing me from updating 100,000+ tasks. 

 

Trigger

 

trigger TaskTrigger on Task (after insert, after update)
{
if(trigger.isAfter) TaskActions.UpdateLastActivityDate(trigger.new);
}

 

Helper Class

 

public with sharing class TaskActions 
{
  static public void UpdateLastActivityDate(List<Task> triggerTasks)
  {
    Set<Id> whatIds = new Set<Id>();
    Set<Id> whoIds = new Set<Id>();
    Set<Id> ownerIds = new Set<Id>();
    for(Task triggerTask:triggerTasks)
    {
      if(!whatIds.contains(triggerTask.WhatId)) whatIds.add(triggerTask.WhatId);
      if(!whoIds.contains(triggerTask.WhoId)) whoIds.add(triggerTask.WhoId);
      if(!ownerIds.contains(triggerTask.OwnerId)) ownerIds.add(triggerTask.OwnerId);
    }
    if(whatIds.size()>0&&ownerIds.size()>0)
    {
      Map<Id,User> ownerMap = new Map<Id,User>([SELECT Id, Profile.Name FROM User WHERE Id IN :ownerIds]);

      Map<Id,Contact> contactMap = new Map<Id,Contact>([SELECT Id, AccountId FROM Contact WHERE Id IN :whoIds]);
      for(Contact contact:contactMap.values()) { if(!whatIds.contains(contact.AccountId)) whatIds.add(contact.AccountId); }

      Map<Id,Applications__c> applicationMap = new Map<Id,Applications__c>([SELECT Id, Dealer__c FROM Applications__c WHERE Id IN :whatIds]);
      for(Applications__c application:applicationMap.values()) { if(!whatIds.contains(application.Dealer__c)) whatIds.add(application.Dealer__c); }

      Map<Id,Contract> contractMap = new Map<Id,Contract>([SELECT Id, AccountId FROM Contract WHERE Id IN :whatIds]);
      for(Contract contract:contractMap.values()) { if(!whatIds.contains(contract.AccountId)) whatIds.add(contract.AccountId); }

      Map<Id,Account> accountMap = new Map<Id,Account>([SELECT Id, Last_Activity_Date_ACA__c, Last_Activity_Date_AF__c, Last_Activity_Date_AFN__c FROM Account WHERE Id IN :whatIds]);

      Map<Id,Account> accountUpdateMap = new Map<Id,Account>();
      for(Task triggerTask:triggerTasks) 
      {
        Account account = accountUpdateMap.get(triggerTask.WhatId);
        if(account==null) account = accountMap.get(triggerTask.WhatId);
        if(account==null)
        {
          Applications__c application = applicationMap.get(triggerTask.WhatId);
          if(application!=null) account = accountMap.get(application.Dealer__c);
        }
        if(account==null)
        {
          Contract contract = contractMap.get(triggerTask.WhatId);
          if(contract!=null) account = accountMap.get(contract.AccountId);
        }
        if(account==null)
        {
          Contact contact = contactMap.get(triggerTask.WhoId);
          if(contact!=null) account = accountMap.get(contact.AccountId);
        }
        User owner = ownerMap.get(triggerTask.OwnerId);

        if(account!=null&&owner!=null)
        {
          if(owner.Profile.Name.Contains('ACA')||Test.isRunningTest()) account.Last_Activity_Date_ACA__c = triggerTask.LastModifiedDate.Date();
          if(owner.Profile.Name.Contains('AFN')||Test.isRunningTest()) account.Last_Activity_Date_AFN__c = triggerTask.LastModifiedDate.Date();
          if((!owner.Profile.Name.Contains('AFN')&&owner.Profile.Name.Contains('AF'))||Test.isRunningTest()) account.Last_Activity_Date_AF__c = triggerTask.LastModifiedDate.Date();

          //for testing only
          //account.Last_Activity_Date_ACA__c = triggerTask.LastModifiedDate.Date();
          //account.Last_Activity_Date_AFN__c = triggerTask.LastModifiedDate.Date();
          //account.Last_Activity_Date_AF__c = triggerTask.LastModifiedDate.Date();

          accountUpdateMap.put(account.Id,account);
        }
      }
      if(accountUpdateMap!=null&&accountUpdateMap.values().size()>0) update accountUpdateMap.values();
    }
  }

  static private testMethod void testAccountActions()
  {
    Account account = [SELECT Id, OwnerId FROM Account ORDER BY LastModifiedDate DESC LIMIT 1];
    Applications__c application = [SELECT Id, OwnerId FROM Applications__c WHERE Dealer__c != null ORDER BY LastModifiedDate DESC LIMIT 1];
    Contract contract = [SELECT Id, OwnerId FROM Contract WHERE AccountId != null ORDER BY LastModifiedDate DESC LIMIT 1];
    Contact contact = [SELECT Id, OwnerId FROM Contact WHERE AccountId != null ORDER BY LastModifiedDate DESC LIMIT 1];

    List<Task> tasks = new List<Task>();
    tasks.add(new Task(WhatId=account.Id,OwnerId=UserInfo.getUserId()));
    tasks.add(new Task(WhatId=application.Id,OwnerId=UserInfo.getUserId()));
    tasks.add(new Task(WhatId=contract.Id,OwnerId=UserInfo.getUserId()));
    tasks.add(new Task(WhoId=contact.Id,OwnerId=UserInfo.getUserId()));
    Test.StartTest();
    insert tasks;
    tasks = [SELECT Id, WhatId, WhoId, LastModifiedDate, OwnerId FROM Task WHERE Id IN:tasks];
    UpdateLastActivityDate(tasks);
    Test.StopTest();
  }
}

AJSFDCAJSFDC

Hi,

 

I just had a quick look and my suggestion is to switch lines 65 to 66 and 66 to 65 on the helper class. Hope it works.

 

Cheers,

J

sf_evolutionsf_evolution

Hi-

 

Can you post the error message?

It looks like the code is bulkified, (although you do have a significant amount of SOQL) so you may just be unning up against governor limits for either processing time ir max. number of statements that can be executed.

 

If you're updating huge numbers of tasks via the bulk loader, can you just limit your batch size(s) to at least get around the problem temporarily?

 

 

babrannobabranno

The problem I was having is that when trying to use the data loader and the bulk api regardless of the batch size I am getting an error that it could not gain exclusive access to the record.  I had disabled all jobs prior to trying this as well as making sure it was after hours but I was still getting the errors.  Once I commented out the class and trigger I didn't have any problems.

AJSFDCAJSFDC

Record lock happens for multiple reason. Based on my understanding in your code the parent record(Account) is not ordered. So if the same account record is updated in multiple batches that may cause a lock.   Try to include 'Order By accountid' clause in the contactmap SOQL and 'Order By Id' in AccountMap.SOQL.

 

Cheers,

J

'

babrannobabranno

I added the order but it did not work.  I believe the problem may be that it is trying to update the same account record multiple times in a batch.  The trigger is updating a field on account based on the task being logged.  Similar to the last activity date but updating based on the task owners role.  Does anyone have any idea how i might be able to modify the helper class to allow for the account being updated multiple times in each batch.

babrannobabranno

Another part that I have stuggled with is having the fields only update if the task status is completed and the subject is coaching/mentoring.  I have tried adding these but I cannot figure it out for the life of me.  I appreciate everyone's help and advice.  Thank you again.

AJSFDCAJSFDC

Can you post your updated helper class code?

babrannobabranno

I have put the updated class below.  Thanks again.

 

public with sharing class TaskActions 
{



    static public void UpdateLastActivityDate(List<Task> triggerTasks)
    {
        Set<Id> whatIds = new Set<Id>();
        Set<Id> whoIds = new Set<Id>();
        Set<Id> ownerIds = new Set<Id>();
        for(Task triggerTask:triggerTasks)
        {
            if(!whatIds.contains(triggerTask.WhatId)) whatIds.add(triggerTask.WhatId);
            if(!whoIds.contains(triggerTask.WhoId)) whoIds.add(triggerTask.WhoId);
            if(!ownerIds.contains(triggerTask.OwnerId)) ownerIds.add(triggerTask.OwnerId);
        }
        if(whatIds.size()>0&&ownerIds.size()>0)
        {
            Map<Id,User> ownerMap = new Map<Id,User>([SELECT Id, Profile.Name FROM User WHERE Id IN :ownerIds]);

            Map<Id,Contact> contactMap = new Map<Id,Contact>([SELECT Id, AccountId FROM Contact WHERE Id IN :whoIds Order By AccountId]);
            for(Contact contact:contactMap.values()) { if(!whatIds.contains(contact.AccountId)) whatIds.add(contact.AccountId); }

            Map<Id,Applications__c> applicationMap = new Map<Id,Applications__c>([SELECT Id, Dealer__c FROM Applications__c WHERE Id IN :whatIds Order By Dealer__c]);
            for(Applications__c application:applicationMap.values()) { if(!whatIds.contains(application.Dealer__c)) whatIds.add(application.Dealer__c); }

            Map<Id,Contract> contractMap = new Map<Id,Contract>([SELECT Id, AccountId FROM Contract WHERE Id IN :whatIds Order By AccountId]);
            for(Contract contract:contractMap.values()) { if(!whatIds.contains(contract.AccountId)) whatIds.add(contract.AccountId); }

            Map<Id,Account> accountMap = new Map<Id,Account>([SELECT Id, Last_Activity_Date_ACA__c FROM Account WHERE Id IN :whatIds Order By Id]);

            Map<Id,Account> accountUpdateMap = new Map<Id,Account>();
            for(Task triggerTask:triggerTasks) 
           

            
            {
                Account account = accountUpdateMap.get(triggerTask.WhatId);
                if(account==null) account = accountMap.get(triggerTask.WhatId);
                if(account==null)
                {
                    Applications__c application = applicationMap.get(triggerTask.WhatId);
                    if(application!=null) account = accountMap.get(application.Dealer__c);
                }
                if(account==null)
                {
                    Contract contract = contractMap.get(triggerTask.WhatId);
                    if(contract!=null) account = accountMap.get(contract.AccountId);
                }
                if(account==null)
                {
                    Contact contact = contactMap.get(triggerTask.WhoId);
                    if(contact!=null) account = accountMap.get(contact.AccountId);
                }
                User owner = ownerMap.get(triggerTask.OwnerId);

                if(account!=null&&owner!=null)
                {
                    if(owner.Profile.Name.Contains('ACA')||Test.isRunningTest()) account.Last_Activity_Date_ACA__c = triggerTask.LastModifiedDate.Date();
                    //if(owner.Profile.Name.Contains('AFN')||Test.isRunningTest()) account.Last_Activity_Date_AFN__c = triggerTask.LastModifiedDate.Date();
                    //if((!owner.Profile.Name.Contains('AFN')&&owner.Profile.Name.Contains('AF'))||Test.isRunningTest()) account.Last_Activity_Date_AF__c = triggerTask.LastModifiedDate.Date();

                    //for testing only
                    //account.Last_Activity_Date_ACA__c = triggerTask.LastModifiedDate.Date();
                    //account.Last_Activity_Date_AFN__c = triggerTask.LastModifiedDate.Date();
                    //account.Last_Activity_Date_AF__c = triggerTask.LastModifiedDate.Date();

                    accountUpdateMap.put(account.Id,account);
                }
            }
            if(accountUpdateMap!=null&&accountUpdateMap.values().size()>0) update accountUpdateMap.values();
        }
    }

    static private testMethod void testAccountActions()
    {
        Account account = [SELECT Id, OwnerId FROM Account ORDER BY LastModifiedDate DESC LIMIT 1];
        Applications__c application = [SELECT Id, OwnerId FROM Applications__c WHERE Dealer__c != null ORDER BY LastModifiedDate DESC LIMIT 1];
        Contract contract = [SELECT Id, OwnerId FROM Contract WHERE AccountId != null ORDER BY LastModifiedDate DESC LIMIT 1];
        Contact contact = [SELECT Id, OwnerId FROM Contact WHERE AccountId != null ORDER BY LastModifiedDate DESC LIMIT 1];

        List<Task> tasks = new List<Task>();
        tasks.add(new Task(WhatId=account.Id,OwnerId=UserInfo.getUserId()));
        tasks.add(new Task(WhatId=application.Id,OwnerId=UserInfo.getUserId()));
        tasks.add(new Task(WhatId=contract.Id,OwnerId=UserInfo.getUserId()));
        tasks.add(new Task(WhoId=contact.Id,OwnerId=UserInfo.getUserId()));
        Test.StartTest();
        insert tasks;
        tasks = [SELECT Id, WhatId, WhoId, LastModifiedDate, OwnerId FROM Task WHERE Id IN:tasks];
        UpdateLastActivityDate(tasks);
        Test.StopTest();
    }
}

AJSFDCAJSFDC

Ok. Just checking did you try the same with 50 or 100 records?

babrannobabranno

It worked without a problem with 50 records.

babrannobabranno

I have solved the  portion in regards to the subject and status.

AJSFDCAJSFDC

Great...

AJSFDCAJSFDC

One last question - Do you have any triggers/workflow rules on Account?

babrannobabranno

Yes.  We have 50 worklow rules on Accounts and one trigger/helper class.  I have included those below.  

 

Trigger


trigger AccountTrigger on Account (after insert, after update, before insert, before update) 
{
  if (trigger.isBefore && trigger.isInsert) AccountActions.AssignDealerNumber(trigger.new);
  if (trigger.isAfter) AccountActions.AssignAccountTeamMembers(trigger.new);
  if (trigger.isAfter && trigger.isInsert) AccountActions.CreateInitialAgreements(trigger.new);
  if (trigger.isAfter) AccountActions.DedupDealerNumbers(trigger.new);
}

 

Helper Class

 

public without sharing class AccountActions 
{
  private static integer staticMaxDealerNumber {get; set;}
  private static Id SpartanAccountRecordTypeId = '012E0000000PPmVIAW';
  private static Id SpartanAgreementRecordTypeId = '012E0000000PQ2TIAW';
  private static Id DealerAgreementRecordTypeId = '012E0000000PQ2YIAW';
  
  static public void AssignDealerNumber(List<Account> triggerAccounts)
  {
    //if(Limits.getQueries() < 50)
    //{
      //RecordType spartanRecordType = [Select Id From RecordType WHERE Name = 'Spartan' AND SObjectType='Account' LIMIT 1];
      //if(spartanRecordType!=null)
      //{
        integer maxDealerNumber = 0;
          maxDealerNumber = GetmaxDealerNumber();
          if(maxDealerNumber!=null && maxDealerNumber > 0)
          {
            for( Account account : triggerAccounts)
            {
              if(account.RecordTypeId <> SpartanAccountRecordTypeId && (account.Dealer_Number__c == null || account.Dealer_Number__c==''))
              {
                maxDealerNumber = maxDealerNumber + 1;
                account.Dealer_Number__c = String.valueOf(maxDealerNumber);
              }
            }
          }
      //}
    //}
  }
  
  static public void DedupDealerNumbers(List<Account> triggerAccounts)
  {
    //if(Limits.getQueries() < 50)
    //{
      //RecordType spartanRecordType = [Select Id From RecordType WHERE Name = 'Spartan' AND SObjectType='Account' LIMIT 1];
  
      //if(spartanRecordType!=null)
      //{
        Set<String> dealerNumbers = new Set<String>();
        for(Account account : triggerAccounts)
        {
          if(account.RecordTypeId <> SpartanAccountRecordTypeId && account.Dealer_Number__c!= null && account.Dealer_Number__c != '') dealerNumbers.add(account.Dealer_Number__c);
        }
  
        List<Account> maybeDupAccounts = [Select Id, Dealer_Number__c, RecordTypeId From Account WHERE Dealer_Number__c IN :dealerNumbers ORDER BY CreatedDate];
        
        List<Account> dupAccounts = new List<Account>(); 
        Set<String> nonDupDealerNumbers = new Set<String>();
        for(Account maybeDupAccount : maybeDupAccounts)
        {
          if(nonDupDealerNumbers.contains(maybeDupAccount.Dealer_Number__c))
          {
            dupAccounts.add(maybeDupAccount);
          }
          else
          {
            nonDupDealerNumbers.add(maybeDupAccount.Dealer_Number__c);
          }
        }
        
        if(dupAccounts!=null&&dupAccounts.size()>0)
        {
          integer maxDealerNumber = 0;
  
            maxDealerNumber = GetmaxDealerNumber();
    
            if(maxDealerNumber!=null && maxDealerNumber > 0)
            {
              for( Account account : dupAccounts)
              {
                if(account.RecordTypeId <> SpartanAccountRecordTypeId)
                {
  system.debug('\nmaxDealerNumber='+maxDealerNumber);          
                  maxDealerNumber = maxDealerNumber + 1;
                  account.Dealer_Number__c = String.valueOf(maxDealerNumber);
                }
              }
            }
            update dupAccounts;
        }
      //}
    //}
  }

  private static integer GetmaxDealerNumber()
  {
      if(staticMaxDealerNumber==null||staticMaxDealerNumber<=0)
      {
      AggregateResult[] results = [SELECT MAX(Dealer_Number_Numeric__c) maxDealerNumber FROM Account];
      if (results!=null&&results.size() > 0) 
      {
        staticMaxDealerNumber = integer.valueOf(results[0].get('maxDealerNumber'));
        }
    //  Account maxDealer = [SELECT Dealer_Number_Numeric__c FROM Account ORDER BY Dealer_Number_Numeric__c DESC LIMIT 1];
    //  if(maxDealer!=null) staticMaxDealerNumber = (integer)maxDealer.Dealer_Number_Numeric__c;
      }
    return staticMaxDealerNumber;
  }
  
  static public void AssignAccountTeamMembers(List<Account> allAccounts)
  {
    List<Account> dealerAccounts = new List<Account>(); 
    Set<Id> acaMarketManagerUserIds = new Set<Id>(); 
    for(Account anyAccount : allAccounts)
    {
      if(anyAccount.RecordTypeId == '012E0000000PPsnIAG') 
      {
        dealerAccounts.add(anyAccount);
        if(anyAccount.ACA_Market_Manager__c!=null) acaMarketManagerUserIds.add(anyAccount.ACA_Market_Manager__c);
      }
    }
    
    List<UserAccountTeamMember> userAccountTeamMembers = new List<UserAccountTeamMember>();
    if(acaMarketManagerUserIds!=null&&acaMarketManagerUserIds.size()>0) userAccountTeamMembers = [SELECT Id, OwnerId, UserId FROM UserAccountTeamMember WHERE OwnerId IN :acaMarketManagerUserIds];
     
    List<AccountTeamMember> existingTeamMembers = [SELECT Id, UserId FROM AccountTeamMember WHERE AccountId IN :dealerAccounts];
    //if(existingTeamMembers!=null) delete existingTeamMembers;
    
    Map<Id,User> activeUsers = new Map<Id,User>([SELECT Id FROM User WHERE IsActive=true]);

    List<AccountTeamMember> teamMembersToDelete = new List<AccountTeamMember>();
    for(AccountTeamMember existingTeamMember : existingTeamMembers)
    {
      if(activeUsers.get(existingTeamMember.UserId)!=null) teamMembersToDelete.add(existingTeamMember);
    }
    if(teamMembersToDelete!=null) delete teamMembersToDelete;

    
    List<AccountTeamMember> newTeamMembers = new List<AccountTeamMember>(); 
    List<AccountShare> newAccountShares = new List<AccountShare>(); 
    for(Account dealerAccount : dealerAccounts)
    {
      if(dealerAccount.ACA_Market_Manager__c!=null&&activeUsers.get(dealerAccount.ACA_Market_Manager__c)!=null)
      {
        AccountTeamMember accountTeamMember = new AccountTeamMember();
        accountTeamMember.AccountId = dealerAccount.Id;
        accountTeamMember.UserId = dealerAccount.ACA_Market_Manager__c;
        accountTeamMember.TeamMemberRole = 'ACA Market Manager';
        newTeamMembers.add(accountTeamMember);
        for(UserAccountTeamMember userAccountTeamMember : userAccountTeamMembers)
        {
          if(userAccountTeamMember.OwnerId==dealerAccount.ACA_Market_Manager__c)
          {
            AccountTeamMember defaultAccountTeamMember = new AccountTeamMember();
            defaultAccountTeamMember.AccountId = dealerAccount.Id;
            defaultAccountTeamMember.UserId = userAccountTeamMember.UserId;
            defaultAccountTeamMember.TeamMemberRole = 'ACA Market Manager';
            newTeamMembers.add(defaultAccountTeamMember);
          }
        }
      }
      
      if(dealerAccount.AFN_Market_Manager__c!=null&&activeUsers.get(dealerAccount.AFN_Market_Manager__c)!=null)
      {
        AccountTeamMember accountTeamMember = new AccountTeamMember();
        accountTeamMember.AccountId = dealerAccount.Id;
        accountTeamMember.UserId = dealerAccount.AFN_Market_Manager__c;
        accountTeamMember.TeamMemberRole = 'AFN Market Manager';
        newTeamMembers.add(accountTeamMember);
      }
      
      if(dealerAccount.AF_Market_Manager__c!=null&&activeUsers.get(dealerAccount.AF_Market_Manager__c)!=null)
      {
        AccountTeamMember accountTeamMember = new AccountTeamMember();
        accountTeamMember.AccountId = dealerAccount.Id;
        accountTeamMember.UserId = dealerAccount.AF_Market_Manager__c;
        accountTeamMember.TeamMemberRole = 'AF Market Manager';
        newTeamMembers.add(accountTeamMember);
      }
    }
    if(newTeamMembers!=null) insert newTeamMembers;
    
    List<AccountShare> teamExistingShares = [SELECT Id, AccountId, UserOrGroupId FROM AccountShare WHERE RowCause='Team' AND AccountId IN :dealerAccounts];
    for(integer i=0;i < teamExistingShares.size();i++)
    {
      teamExistingShares[i].AccountAccessLevel = 'Edit';
      teamExistingShares[i].OpportunityAccessLevel = 'None';
      teamExistingShares[i].ContactAccessLevel = 'None';
      teamExistingShares[i].CaseAccessLevel = 'None';
    }
    update teamExistingShares;
  }

  static public void CreateInitialAgreements(List<Account> triggerAccounts)
  {

    //String SpartanAccountRecordTypeId = '012E0000000PPmVIAW';
    //String SpartanAgreementRecordTypeId = '012E0000000PQ2TIAW';
    //String DealerAgreementRecordTypeId = '012E0000000PQ2YIAW';

    //Double check recordtypes
    //List<RecordType> recordTypes = [SELECT Id, Name, SOBjectType FROM RecordType];
    //for(RecordType recordType : recordTypes)
    //{
///      if(recordType.SObjectType=='Account' && recordType.Name=='Spartan') SpartanAccountRecordTypeId = recordType.Id;
//      if(recordType.SObjectType=='Contract' && recordType.Name=='Spartan') SpartanAgreementRecordTypeId = recordType.Id;
//      if(recordType.SObjectType=='Contract' && recordType.Name=='AF/AFN/ACA') DealerAgreementRecordTypeId = recordType.Id;
    //}    
    List<Account> accounts = [SELECT Id, Name, RecordTypeId FROM Account WHERE Id IN :triggerAccounts];
    
    List<Contract> newContracts = new List<Contract>();
    for(Account account : accounts)
    {
      if(account.RecordTypeId != SpartanAccountRecordTypeId)
      {
        Contract newContract = new Contract();
        if(account.RecordTypeId == SpartanAccountRecordTypeId) newContract.RecordTypeId = SpartanAgreementRecordTypeId;
        else newContract.RecordTypeId = DealerAgreementRecordTypeId;
        newContract.AccountId = account.Id;
        newContract.StartDate = system.today();
        newContracts.add(newContract);
      }
    }
    if(newContracts!=null&&newContracts.size()>0) insert newContracts;
  }

  static private testMethod void testAccountActions()
  {
    User acaUser = [SELECT Id FROM User WHERE IsActive=true AND Profile.Name = 'ACA User' LIMIT 1];

    Account account1 = new Account();
    account1.RecordTypeId = '012E0000000PPsnIAG';
    account1.Name = 'TestAccount';
    account1.ACA_Market_Manager__c = acaUser.Id;
    account1.ACA_Dealer_Status__c = 'Active';

    Account account2 = new Account();
    account2.RecordTypeId = '012E0000000PPsnIAG';
    account2.Name = 'TestAccount';
    account2.ACA_Market_Manager__c = acaUser.Id;
    account2.ACA_Dealer_Status__c = 'Active';
    account2.Dealer_Number__c = '500000';

    Account account3 = new Account();
    account3.RecordTypeId = '012E0000000PPsnIAG';
    account3.Name = 'TestAccount';
    account3.ACA_Market_Manager__c = acaUser.Id;
    account3.ACA_Dealer_Status__c = 'Active';
    account3.Dealer_Number__c = '500001';

    List<Account> accounts = new List<Account>();
    accounts.add(account1);
    accounts.add(account2);
    accounts.add(account3);

    Test.StartTest();
  
    insert accounts;

    system.debug('\naccount2.Dealer_Number__c='+account2.Dealer_Number__c);    
    system.debug('\naccount2.Dealer_Number__c='+account2.Dealer_Number__c);    
    AccountActions.AssignDealerNumber(accounts);
    AccountActions.AssignAccountTeamMembers(accounts);

    accounts[0].ACA_Market_Manager__c = acaUser.Id;
    
    update accounts;
    
    AccountActions.AssignAccountTeamMembers(accounts);
    Test.stopTest();
  }

}

AJSFDCAJSFDC

Do you need the trigger and workflow to be fired as part of Task mass update? If not then deactivate account triggers and try.. Otherwise it needs lot of analysis and restrcture of the code...

 

Cheers,

J