I have batch which queries for record in a standard object which has 16 million of records. I am trying to query only few records with checkbox checked using querylocator to delete it . However the query takes too long to process and times out. The query used is "Select id, Delete_Social_Post__c,xxx_c,ExternalId_c, CreatedDate From SocialPost where Delete_Social_Post__c = true Order by createddate asc "


  • instead of createddate try with systemModStamp Nov 7, 2016 at 8:02

1 Answer 1


You can improve your performance with selecting indexed fields - you should read about performance patterns like this:

Improve performance with Custom indexes using Selective SOQL Queries

  • Hi Itai, I could not make the query more selective. May be i will have to request Salesforce to add custom index to the checkbox field i add in the query. Please let me know if there are any other options for the same Nov 7, 2016 at 7:45
  • This is a good option, you can try to narrow down your search first with an indexed column, see if it helps, then change it back Nov 7, 2016 at 7:52
  • Using selective queries is THE best option but in the event of this not being possible, you could also use LIMIT/OFFSET to show limited number of records and then query more assuming this is happening on a VF page.
    – SF Learner
    Nov 7, 2016 at 23:17

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.