I have a batch class with a query string in which I want to limit the query to records last modified before a datetime, but the '<' char seems to need escaping and I can't find any documentation to tell me how. I have a dim and distant memory of using & lt; but that doesn't seem to work either.


eg global database.querylocator start(Database.BatchableContext BC) {

    String todaysDate = string.valueof(date.today());
    string query = 'Select Id, Name, StageName, CloseDate FROM Opportunity'
        + 'where LastModifiedDate < 2013-07-23T12:00:00.000Z';

    return Database.getQueryLocator(query);

gives me a run time error on the '<' and if I use & lt; in its place.

  • You don't ordinarily use &lt; in Apex Code (you're thinking of JavaScript/HTML). When in doubt for situations like this, always try a System.debug (e.g. System.debug(query)), which will usually help outline the problem.
    – sfdcfox
    Jul 23, 2013 at 16:02

1 Answer 1


I think the error message is misleading. You're missing a space between 'Opportunity' and 'where'.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.