I have a task to perform a fairly large and specific data removal.
The goal is to remove all EmailMessage objects that have a parent Case record whose status is closed, from BEFORE a certain date. The problem i think is that the inner query on Cases is returning a lot of records - around 60,000.
The query that i need the result for is this:
select id from emailmessage where parentid in (select id from case where status = 'closed' and closeddate < 2014-11-01T00:00:00.000Z)
Here are the methods that have tried with their resultant issues:
Salesforce Developer Console. Query takes too long and times out.
Data Loader command line interface. Not possible because this method allows for inner queries but does NOT allow for a date filter.
Python API. This allows me to run the query successfully and in Sandbox environment with minimal data returns successfully. In production, it times out due to the large volume of data.
It would be great if i could split up the query by limiting the inner query, but the limit keyword is not allowed within an inner query.