Skip to main content
I created the following Batch apex code to delete the records created on March 29th, 2016 from the account object. The records are deleted if the query is

 

'select Id,name from Account '

 

but the following query in the code doesn't work. Any mistake in the code? 

 

Please help!

 

global class BatchImpl implements Database.Batchable<sObject>

 

{

 

    global Database.QueryLocator Start(Database.BatchableContext bc)

 

    {

 

       String sql='select Id,name from Account where CreatedDate="2016-03-29T16:02:11.000Z"';  

 

       return Database.getQueryLocator(sql);  

 

    }

 

    

 

    global void execute(Database.BatchableContext bc, List<Account> a)

 

    {

 

         delete a;

 

    }

 

    global void finish(Database.BatchableContext bc)

 

    {

 

        

 

    }

 

}
1 answer
  1. May 10, 2016, 8:18 PM

    The issue is this :

     String sql='select Id,name from Account where CreatedDate="2016-03-29T16:02:11.000Z"';  

    make it like 

    DateTime myDate = DateTime.newInstance(2016, 3, 29, 2, 11, 0);

    String sql='select Id,name from Account where CreatedDate=:myDate';

     

    Please post this to developer forum for faster response.

    https://developer.salesforce.com/forums/

0/9000