You need to sign in to do that
Don't have an account?
Puja Dev 6
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" error at the time of bulk data import.
Hi All,
Please help me to bulkiefy the following :
private void getAccountD(List<Account> acc){
List<Account> account = new List<Account>();
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c];
for(State_Master__c e : SM){
for(Account g : acc){
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
}
}
if(account.size() <= 0){
for(Account g : acc){
g.Sales_Office_Text__c = '';
g.Sales_District_Text__c = '';
g.Sales_Group_Text__c = '';
account.add(g);
}
}
}
It is working fine for individual record insert and update event.
But it gives
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" this error at the time of bulk data import.
Thanks in Advance,
Puja
Please help me to bulkiefy the following :
private void getAccountD(List<Account> acc){
List<Account> account = new List<Account>();
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c];
for(State_Master__c e : SM){
for(Account g : acc){
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
}
}
if(account.size() <= 0){
for(Account g : acc){
g.Sales_Office_Text__c = '';
g.Sales_District_Text__c = '';
g.Sales_Group_Text__c = '';
account.add(g);
}
}
}
It is working fine for individual record insert and update event.
But it gives
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" this error at the time of bulk data import.
Thanks in Advance,
Puja
Yes there are 4 workflow rules on the same object i.e. on Account
Your Code is throwing the error because your Apex execution time is too long. Salesforce has defined certain governor limits which are to be followed while we code.
The Maximum CPU time on the salesforce servers is 10,000 milliseconds for Synchronous apex and 60,000 milliseconds for Asynchronous apex.
Using nested for loop works fine upto certain limit but it fails for bulk data Load.
Solution:-
1. You can limit the amount of records Queried like below:
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c LIMIT 500];
2. You can use a Map instead of double for loop.
Thanks,
Ajay
I have 40000 records for State Master.
Can you please give me any sample code for MAP...?
Or help me to figure out this problem...?
Can you brief me about the functionality of your Trigger?
Thanks
Ajay
State Master contains Zone__c,Territory_Code__c,RO__c. I have to populate this fields on Account.
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
Please try once using sets and maps below are sample codes to avoid CPU time limit error.
Please let me know in case of any other help.
Thanks
Varaprasad