I have a batch class to update case object. When i am running this job, getting an error: Too many SOQL queries.
Can some one help me to write the 'query on feeditem' out side of the for loop in EXECUTE method.
Here is my code.
global class BatchtoUpdateBusinessDays implements Database.Batchable { Public final String Query;
global BatchtoUpdateBusinessDays() {
query = 'SELECT Id,Status,No_of_Days_Case_Untchd_Business_Days__c FROM Case WHERE Status != \'Closed\' or Status != \'Duplicate\' or Status != \'Deleted\'';
}
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Case> scope) {
list<businesshours> bh = new List<businesshours>([select id,Name from businesshours where Name = 'Working Days']);
for(Case c : scope)
{
String BusinessHours_Id = bh[0].Id;
list<Feeditem> FIlist = new list<Feeditem> ([Select Id, CreatedDate from Feeditem where parentId = :c.Id]);
Long Mins_since_lastTouched = BusinessHours.diff (BusinessHours_Id, FIlist[0].CreatedDate, System.Now()) / 1000 / 60;
System.debug('<<<<>>>>'+ Mins_since_lastTouched );
c.No_of_Days_Case_Untchd_Business_Days__c = Mins_since_lastTouched / 24 / 60;
System.debug('<<<<>>>>'+ c.No_of_Days_Case_Untchd_Business_Days__c );
}
update scope;
}
global void finish(Database.BatchableContext BC) {
} }
FeedItem
.