function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hanna BergsmaHanna Bergsma 

Scheduled Flow to Delete Email Messages- "Failed to Delete Records"

I am trying to create a flow that deletes email messages over 2 years old. When I run the flow, however, I get a "Failed to delete records that meet the filter criteria." I've included screenshots of this very simple flow. I'm only filtering on status and LastModifiedDate so no records should have null values for either of those.

thank you!
User-added image
User-added imageUser-added imageUser-added image
RituSharmaRituSharma
Debug your flow step by step to figure out the problematic step.

The point to note is that Admins with 'Modify All Data'  may delete EmailMessage records as long as they're not in an orphaned state.
AbhishekAbhishek (Salesforce Developers) 
Hi Hanna,

Based on your Error ID I have looked into our server logs and the below information,

common.apex.runtime.impl.ExecutionException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)



Based on this Error ID:- -548403183  I would suggest you raise a case with the Salesforce support team.

To resolve your issue Indexing needs to done and it will be done only by the salesforce support team.

Raise a case and Provide the details I have mentioned so they will perform the indexing(It will be done even you don't have premier support)


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.
Hanna BergsmaHanna Bergsma

Abhishek,

Thanks for your reply! I opened a case and unfortunately they said their basic support couldnt help me. Im going to push more as it seems like it should be possible based off their own published documentation.

Hoping this is the solution that fixes the flow!