You need to sign in to do that
Don't have an account?
![ss123 ss123](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
query timing out anyother way to use same query
All contacts from Account name =0017000000qz98bAAA with no case attched to them will be deleted
it is timing out
code for query is in following message
purge code not working in production but it is working in Full sandbox
SELECT Id FROM Contact WHERE CreatedDate <=:startDate AND AccountId = '0017000000qz98bAAA' AND id not in (select ContactId from Case) LIMIT 10000]
millions and millions
so i need to use more ands to make the execution time less ot need a diffrent query with same output to use with data loader
Its difficult to process such big no. of records in apex without a batch job.
I see few options here.
1) Create a report in SFDC , run that report and extract the csv file . Use it to delete the records using the data loader.
2) Put more filters in your query.
The problem with your query is even if you have a limit 10000 it has to scan through the entire case object ( this object also could have millions of rows)
Try to Save 10000 records (Contacts in a list....by applying first 2 filters)
and then right another query on case object to scan these 10000 records.
Now you will get 1 more list.
Difference between these 2 lists can be used to delete the required contact records.
Thanks let me try this see if this will work
what about creating a list of only few records and running that query on thta list is that possible
You can break your query like this it may improve the performance.
Looking at your query, I would suspect that this clause is your problem:
How many case records are in your system? I suspect it is timing out because you are querying all of them in this subquery.