0

I have below apex batch query string which fails to execute for which seems to be an issue with escape character required. Can someone help me here?

global Database.QueryLocator start(Database.BatchableContext bc) {
    Date d = Date.today();
    String soql = 'SELECT Id, Name, Publish_Date_abv__c FROM Compliance_Incident_abv__c' +
        ' WHERE Publish_Date_abv__c+14 =: d';
    // above line fails to execute
    return Database.getQueryLocator(soql);
}
0

2 Answers 2

4

You are using invalid SOQL, Publish_Date_abv__c+14 is not a valid field. Instead, modify the Date value you are comparing against.

Date twoWeeksAgo = Date.today().addDays(-14);

Then just compare against the above value in your string:

WHERE Publish_Date_abv__c = :twoWeeksAgo
2

Instead of the +14, change d to be the data - 14 when populating the value for d

global Database.QueryLocator start(Database.BatchableContext bc) {
    Date d = Date.today().addDays(-14);
    String soql = 'SELECT Id, Name, Publish_Date_abv__c FROM Compliance_Incident_abv__c WHERE Publish_Date_abv__c =: d';
    // above line fails to execute
    return Database.getQueryLocator(soql);
}

You must log in to answer this question.

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