+ Start a Discussion
Sohan ShirodkarSohan Shirodkar 

How do delete Email Message records?

Email Message records are consuming a lot of storage in my org. If I try to delete through developer console it throws "insufficient access rights on object id" error.

An article here (https://help.salesforce.com/articleView?id=emailadmin_enhanced_email_considerations.htm&type=5) says:
"The email sender and an admin with the appropriate permissions can delete an email message."

Can someone help me understand what is that "appropriate permission" which admins need to delete an Email Message record?
Best Answer chosen by Sohan Shirodkar
Sohan ShirodkarSohan Shirodkar
The article below helped me out: 
https://help.salesforce.com/articleView?id=000323372&language=en_US&type=1&mode=1

The point to note is Admins with 'Modify All Data'  may delete EmailMessage records as long as they're not in an orphaned state.
This was exactly the case with me.
 

All Answers

Team NubesEliteTeam NubesElite
Hi Sohan,
The workaround that was proposed (and I took it) was to enable "login as" for all users on the organization, and give them temporarily the permission "author apex" so I could login as them and open the developer console to execute the query to delete the records.
List<EmailMessage> emList =[SELECT Id FROM EmailMessage]; 
system.debug(emList); 
delete emList;
after that all EmailMessage should be gone. You can run the first two lines again to make sure that there are cero records.
List<EmailMessage> emList =[SELECT Id FROM EmailMessage]; 
system.debug(emList);


Thank You
www.nubeselite.com

Developement | Training | Consulting

Please Mark this assolution if your problem resolved.
 
Sohan ShirodkarSohan Shirodkar
Hi 

System admin has "author apex" permission. Why is he unable to delete Email Message using the code snippet through execute anonymous window?
Team NubesEliteTeam NubesElite
Hi Sohan,
As of now Inbound Email Message and Email Message Relation is not deletable by System Admin
If Email Message Relation is not available you cannot delete Email Message as well


Thank You
www.nubeselite.com

Developement | Training | Consulting

Please Mark this as solution if your problem resolved.
Sohan ShirodkarSohan Shirodkar
The article below helped me out: 
https://help.salesforce.com/articleView?id=000323372&language=en_US&type=1&mode=1

The point to note is Admins with 'Modify All Data'  may delete EmailMessage records as long as they're not in an orphaned state.
This was exactly the case with me.
 
This was selected as the best answer