+ Start a Discussion

Apex query issues

I just introduced a new custom object KE__c. I want to run through all the existing contacts and tasks associated with those contacts to insert a new item in this custom object and delete the associated tasks simultaneously. Each item in the custom object would copy some fields from the contacts. I figured that I can set a scheduled job and have a class to query for the required data and loop throught them. The problem is that an apex query would only return upto 10000 records and we have around 250000 contacts . Any idea or an example to query and loop through the entire set of contacts.



Have a look at Batch Apex, it's probably what you're looking for,