You need to sign in to do that
Don't have an account?
Gabe Rothman 8
Can anyone help me to bulk-safe this class? Any help would be greatly appreciated...
I'm trying to do a data-load of 3000 records, but it's failing because I'm hitting my query limit. I've had to limit my batch size to 1 record at a time in order to successfully allow Lexi Loader to work. The offending class is pasted below, can anyone help me bulkify it? Thanks!
public with sharing class setAccountGeoFromCountryService { public static void updateGeo(List<Account> Accounts) { List<String> listCountries = new List<String>(); List<String> listStates = new List<String>(); List<String> listZips = new List<String>(); for (Account a : Accounts) { if(a.BillingCountry == null){ return; } if(a.BillingCountry != null){ listCountries.add(a.BillingCountry ); if(a.BillingCountry != 'US'){ listStates.add('NULL'); listZips.add('NULL'); } if(a.BillingCountry == 'US'){ listStates.add(a.BillingState ); if(a.BillingState == 'CA' || a.BillingState == 'California'){ listZips.add(a.BillingPostalCode); } if(a.BillingState != 'CA' && a.BillingState != 'California'){ listZips.add('NULL'); } } } } try{ Territories__c territory = [SELECT Country_Code__c, Region__c, Theater__c, Country__c, State__c, State_Code__c, Postal_Code__c FROM Territories__c WHERE Country_Code__c IN: listCountries AND (State__c =: listStates OR State_Code__c =: listStates) AND Postal_Code__c =: listZips]; system.debug(territory); for (Account a2: Accounts){ if(a2.Owner_is_Federal__c==true){ a2.Geography__c = 'Federal'; a2.Country2__c = territory.Country__c; a2.Region__c = territory.Region__c; } if(a2.Owner_is_Federal__c==false){ a2.Geography__c = territory.Theater__c; a2.Country2__c = territory.Country__c; a2.Region__c = territory.Region__c; } } }catch(QueryException e){} } }
NOTE: This code has not been tested and may contain typographical or logical errors
All Answers
NOTE: This code has not been tested and may contain typographical or logical errors