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

Modification of query for Start method in Batch job

Hello all,


I was wondering if there is any way to modify the following query to limit the results to only  records that were updated after the last batch job 'EmailBatch'  was either ran or completed?


query = 'select id,email,hasoptedoutofemail,lastmodifieddate from contact order by email asc,lastmodifieddate asc'; 

The query is currently being used in the start method of a batch apex and I have been constantly receiving following error. (Note I scheduled this job couple of days ago at a particular time and the error was displayed. Next day, the batch was processed perfectly. And again the error occurs today.)


First error: SQLException [java.sql.SQLException: ORA-01013: user requested cancel of current operation
: select /*ApexBatch.Class.EmailOptOutBatch.start: line 26*/ *
from (select "Id"
from (select upper( "_SORT_COL_0",
t.last_update "LastModif...


Thanks for your time!!


Actually, I need to query the records that were updated or modified since the last time a batch job ran. Any guidance?