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
plapla 

Mass update and trigger issue

Hello,

 

I wrote a before update, before insert trigger to update account records whenever an account is edited or created. When I manually update or create an account, the record is updated as expected. However when I use dataloader to do mass update of the account records, it does not work as expected. There are some records are updated and some other records are not updated. It looks like there are too many records to update at the same time when I do a mass update. What is the best approach to resolve this issue? Please advise.

 

Thanks

Paul

 

Arun MKArun MK

 

Hi,

 

Does your triggers handle the bulk data? If not, it might result in not working of data.

 

If you want more help, share your trigger code so that I can try to optimize it to work for bulk data.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

 

Regards,

Arun

plapla

Hello,

Below is the entire trigger codes. Any help is appreciated. Would after insert, after update help in this case?

 

trigger AccountRegion on Account (before insert, before update) {
  String State;
  String Region;
  String Carrier;
  String AccountNum;
  String AccountType;
  String FundingType;
  Boolean Processed = true;
 
  Set<string> WestRegion = new Set<string>{'WA','OR','CA','ID','NV','AZ','UT','MT','WY','CO','NM','AK','HI'};
  Set<string> CentralRegion = new Set<string>{'ND', 'SD', 'NE', 'KS', 'OK', 'TX', 'MN','IA','MO','WI','IL','IN','OH','MI','KY'};
  Set<string> Northeast = new Set<string>{'WV','VA','PA','NY','VT','ME','NH','MA','CT','RI','NJ','DE','DC'};
  Set<string> Southeast = new Set<string>{'AR','LA','MS','AL','TN','GA','SC','NC','FL'};
  Set<string> Carriers = new Set<string>{'PSI5000', 'PSI5002', 'PSI5004', 'PSI5006', 'PSI5008', 'PSI5010', 'PSI5012', 'PSI5014', 'PSI5016' };
 
  for(Account AccountUpdated:trigger.new){
   
//process only record type = Group, CM and CM Carrier
  if ((AccountUpdated.RecordTypeId == '012a0000001FdyhAAC') || (AccountUpdated.RecordTypeId == '01230000000XhdNAAS') || (AccountUpdated.RecordTypeId == '012a0000001FldcAAC')){  
   
   Carrier = AccountUpdated.Carrier_ID__c;
   AccountNum = AccountUpdated.AccountNumber;
 
   if (AccountNum != null){
      if ((AccountNum).length() > 1){
         AccountNum = (AccountNum).right(1);
      }     
   }
     // System.debug('AccountRegion/Carrier: ' + Carrier);

   if (Carrier != null){   

 //Fresh Start ACIS & Connectivity ACIS
      if ((Carrier.toUpperCase().startsWith('UHCAC')) || (Carrier.toUpperCase() == 'UHGUP0001' && AccountNum == 'U')){
      
         Processed = false;
         State = AccountUpdated.RxClaim_Mailing_State__c;
        
         // Region
         if (State != null){
      
            if(WestRegion.contains(State.toUpperCase())){
                Region = 'West';
            } else if (CentralRegion.contains(State.toUpperCase())){
                Region = 'Central';
            } else if (Northeast.contains(State.toUpperCase())){
                Region = 'Northeast';
            } else if (Southeast.contains(State.toUpperCase())){
                Region = 'Southeast';
            }
           
            AccountUpdated.Region__c = Region;
           
          } // End of Region
     
          // Account Type
          AccountType = AccountUpdated.Segment_Indicator__c;
         
          if (AccountType != null){
             if(AccountType == 'NM'){
                AccountType = 'National Accounts';
             } else if (AccountType == 'MM1'){
                AccountType = 'Key Accounts 51-500 lives';
             } else if (AccountType == 'MM2'){
                AccountType = 'Key Accounts 501-2000 lives';
             } else if (AccountType == 'MM3'){
                AccountType = 'Key Accounts 2001-10,000 lives';
             } else if (AccountType == 'SG'){
                AccountType = 'Small Group';
             }
            
             AccountUpdated.Segment_Indicator__c = AccountType;
            
          } // End of Account Type
         
          FundingType = AccountUpdated.Funding_Arr_Indicator__c;
         
          if (FundingType != null){
             if (FundingType == 'A'){
                FundingType = 'ASO';
             } else if (FundingType == 'F'){
                FundingType = 'Fully Insured';
             } else if (FundingType == 'H'){
                FundingType = 'ACEC Hybrid';
             }
            
             AccountUpdated.Funding_Arr_Indicator__c = FundingType;
          }
           
      }
// End of Fresh Start ACIS & Connectivity ACIS


// Start of AMS
      if (Processed){
     
        if(Carriers.contains(Carrier.toUpperCase())){
           Region = 'Central';
           AccountType = 'Key Account';
           FundingType = 'Fully Insured';
        
           AccountUpdated.Region__c = Region;
           AccountUpdated.Segment_Indicator__c = AccountType;
           AccountUpdated.Funding_Arr_Indicator__c = FundingType;
        
           Processed = false;
        }
      }
// end of AMS

   
  
// FS Student Resources  
      if (Processed){
       
       if (Carrier.toUpperCase().equals('UHCSTRC01')){
        
        State = AccountUpdated.Situs_State__c;
     //   System.debug('AccountRegion/FS Student Resources/State: ' + State);
         if (State != null){
      
            if(WestRegion.contains(State.toUpperCase())){
                Region = 'West';
            } else if (CentralRegion.contains(State.toUpperCase())){
                Region = 'Central';
            } else if (Northeast.contains(State.toUpperCase())){
                Region = 'Northeast';
            } else if (Southeast.contains(State.toUpperCase())){
                Region = 'Southeast';
            }
           
            AccountUpdated.Region__c = Region;
           
          } // End of Region
         
          FundingType = AccountUpdated.Funding_Arr_Indicator__c;
         
          if (FundingType != null){
             if (FundingType == 'A'){
                FundingType = 'ASO';
             } else if (FundingType == 'F'){
                FundingType = 'Fully Insured';
             } else if (FundingType == 'H'){
                FundingType = 'ACEC Hybrid';
             }
            
             AccountUpdated.Funding_Arr_Indicator__c = FundingType;
          }
         
          Processed = false;
        
       }
       
      } // end of FS Student Resources


    
     
    } // Carrier
  
   }  // Record type = Group
 
  } // for structure
}

Arun MKArun MK

Hi,

 

I think the problem is around the boolean variable Processed.

 

Initialize the Processed variable to true immediatley after the for loop.

 

for(Account AccountUpdated:trigger.new){

Processed = true;

...

...

...

}

 


If this post is helpful please throw Kudos.
If this post solves your problem kindly mark it as solution.

 

Regards,

Arun.

plapla

Thanks so much. You are great help. It works fine now.

 

Paul