function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDCboxSFDCbox 

Efficient SOQL in Batch Start method

Hello All,

I am writing a batch and have got the following query. This is working fine but need some ideas if there is a room to improve this query so that i do encounter any error on this.
 
List<Case> allCaseWithEventList = [select id, casenumber,(SELECT whatid, ActivityDateTime,EndDateTime,Id,StartDateTime,Subject,Type FROM Events where isDeleted = false and recordtype.developername = 'Mock_Back') from case where  status = 'New' and campaign__c <> null and campaign__c in (select id from campaign where enddate <= TODAY)];
        for(Case case_to_close : allCaseWithEventList){
            if(case_to_close.status=='Call_Back' && case_to_close.Events!=Null){
                for(Event eve : case_to_close.Events){
                    if(eve.EndDateTime <> null && eve.EndDateTime <= System.now()){
                        if(eve.Type <> null && (eve.Type <> 'DMC Call Back' && eve.Type <> 'Non DMC Call Back' && eve.Type <> 'Renewal Date Call back') ){
                            setofCaseIdsToBeClosed.add(eve.whatid);
                        }
                    }
                }
            }



Many Thanks

            if(case_to_close.status=='New' && case_to_close.Events == Null){
                setofCaseIdsToBeClosed.add(case_to_close.Id);
            }
        }