Hi I'm new to Salesforce Please Help me the Following SOQL Avoid in FOR loops.
Issue: When We Update Read__c (Checkbox) Field in Book sObject and In Cases Update (Recent_Record__c) field.
Thanks in Advance Manu
Helper Class
public class RecentReadInCase{
public static case cas;
Public static void mostRecentRead (List<Book__c> bkList){
List<Case> caslst = [SELECT CaseNumber,Recent_Record__c,(select name,Read__c from book__r) FROM Case where Recent_Record__c = false];
if(caslst != null){
for(Book__c b : bkList){
cas = [select id,casenumber,Recent_Record__c from case where id =: b.Case_Number__c limit 1];
if(cas != null)
cas.Recent_Record__c = true;
}
update(cas);
}
}
}
Trigger
trigger MostRecentFlagCaseTrig on Book__c (After insert,After Update) {
if(trigger.isAfter){
if(trigger.isInsert || trigger.isUpdate){
MostRecentReadInCase.mostRecentRead(trigger.new);
}
}
}