You need to sign in to do that
Don't have an account?
harsha vardhan vasa 9
Hi Team, getting apex cpu time limit exceeded for the bacth class with batch size 2
Hi Team,
below is the code snippet. getting cpu time limit exceeded for the batch size 2 also. any optimization can be done to the following code.
the premise object scoped records are 6.7 million.
public class batchUpdatetable implements Database.Batchable<sObject> {
Id resedentialRT = Schema.SObjectType.EI_Site__c.getRecordTypeInfosByName().get('Residential').getRecordTypeId();
public Database.QueryLocator start(Database.BatchableContext BC){
String Query;
return database.getquerylocator('select id,(select id from Site_Service_Agreements__r where recordtypeId=:resedentialRT ),CENSUS_TRACT__c,Cal_Enviro_Version_EI__c,CS_GT_Legacy_DAC__c from EI_PREMISE__c LIMIT 99999');
}
public void execute(Database.BatchableContext BC, List<EI_PREMISE__c> scope){
List<EI_PREMISE__c> prToUpdate = new List<EI_PREMISE__c>();
list<EI_CensusTract_temp__c> templist = new list<EI_CensusTract_temp__c>([select id,Cal_Enviro_Version_EI__c,Census_Tract_EI__c,CS_GT_Legacy_DAC__c from EI_CensusTract_temp__c]);
map<string,EI_CensusTract_temp__c> tempmap = new map<string,EI_CensusTract_temp__c>();
for(EI_CensusTract_temp__c t:templist){
tempmap.put(t.Census_Tract_EI__c,t);
}
for(EI_PREMISE__c s : scope){
if(tempmap.containsKey(s.CENSUS_TRACT__c)){
s.CS_GT_Legacy_DAC__c = tempmap.get(s.CENSUS_TRACT__c).CS_GT_Legacy_DAC__c;
s.Cal_Enviro_Version_EI__c = tempmap.get(s.CENSUS_TRACT__c).Cal_Enviro_Version_EI__c;
//s.DAC_CA__c = tempmap.get(s.CENSUS_TRACT__c).DAC_CA__c;
prToUpdate.add(s);
}
}
update prToUpdate;
}
public void finish(Database.BatchableContext BC){
}
}
below is the code snippet. getting cpu time limit exceeded for the batch size 2 also. any optimization can be done to the following code.
the premise object scoped records are 6.7 million.
public class batchUpdatetable implements Database.Batchable<sObject> {
Id resedentialRT = Schema.SObjectType.EI_Site__c.getRecordTypeInfosByName().get('Residential').getRecordTypeId();
public Database.QueryLocator start(Database.BatchableContext BC){
String Query;
return database.getquerylocator('select id,(select id from Site_Service_Agreements__r where recordtypeId=:resedentialRT ),CENSUS_TRACT__c,Cal_Enviro_Version_EI__c,CS_GT_Legacy_DAC__c from EI_PREMISE__c LIMIT 99999');
}
public void execute(Database.BatchableContext BC, List<EI_PREMISE__c> scope){
List<EI_PREMISE__c> prToUpdate = new List<EI_PREMISE__c>();
list<EI_CensusTract_temp__c> templist = new list<EI_CensusTract_temp__c>([select id,Cal_Enviro_Version_EI__c,Census_Tract_EI__c,CS_GT_Legacy_DAC__c from EI_CensusTract_temp__c]);
map<string,EI_CensusTract_temp__c> tempmap = new map<string,EI_CensusTract_temp__c>();
for(EI_CensusTract_temp__c t:templist){
tempmap.put(t.Census_Tract_EI__c,t);
}
for(EI_PREMISE__c s : scope){
if(tempmap.containsKey(s.CENSUS_TRACT__c)){
s.CS_GT_Legacy_DAC__c = tempmap.get(s.CENSUS_TRACT__c).CS_GT_Legacy_DAC__c;
s.Cal_Enviro_Version_EI__c = tempmap.get(s.CENSUS_TRACT__c).Cal_Enviro_Version_EI__c;
//s.DAC_CA__c = tempmap.get(s.CENSUS_TRACT__c).DAC_CA__c;
prToUpdate.add(s);
}
}
update prToUpdate;
}
public void finish(Database.BatchableContext BC){
}
}
try with below code.
If this helps, Please mark it as best answer.
Thanks!!