0
`global class CoolOfPeriodNotificationBatch implements Database.batchable<sObject> {

   // private static final String soqlQuery = 'select Id,owner.name from opportunity';
    global Database.QueryLocator start(Database.BatchableContext BC)
    {


        String query = 'select Id,owner.name from opportunity where in_Cool_Off_Period__c=true and DAY_ONLY(Cool_off_Period_Start_DateTime__c)=:DAY_ONLY(Sytem.Today().adddays(-26))';



        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<opportunity> scope)
    {
        List < Messaging.SingleEmailMessage > mailList = new List < Messaging.SingleEmailMessage > (); 

        for(opportunity ac:scope){

            system.debug('ac'+ac); 
        }        

    }

    global void finish(Database.BatchableContext BC){ 

    }
}`

1 Answer 1

1

Dynamic SOQL does not support expressions, only simple bind expressions. Use an inline query instead. Also, there is no need to use DAY_ONLY for a Date (the second one is not necessary).

return Database.getQueryLocator([
  select Id,owner.name 
  from opportunity 
  where in_Cool_Off_Period__c=true and 
  DAY_ONLY(Cool_off_Period_Start_DateTime__c)=:Sytem.Today().adddays(-26)      
]);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .