0

I'm have a system administrator profile and I can't delete all the email messages (EmailMessage object) on my organization. What can I do? I've tried running Apex queries with the delete statement and also tried to use the Data Loader, but I get insufficient privileges on every one of those options. It is really weird because I can't access the record on the organization, but I can query the fields normally (I still have access to the information).

  • 1
    With you having access to execute queries you could run "SELECT RecordId FROM UserRecordAccess WHERE UserId=:UserInfo.getUserId() AND HasReadAccess = true AND RecordId IN :allRecordIds LIMIT 200". allRecordIds will be a list of EmailMessage Ids. There may be some access rights your not aware of. This would be first step. – TSmith Mar 8 '17 at 19:50
  • I got 0 records with acces. But that is exactly my point: I'm a System Administrator. I should be able to delete any record in the system. – Renato Oliveira Mar 8 '17 at 19:59
2

Due to an unidentified issue in my organization, some EmailMessage records were created without some references, and even I, as administrator, couldn't delete or read the records by the UI. I could see them on the developer console, when executing a query, but couldn't change them in any way.

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.

While this worked, it is far from the ideal (which would be to be able to delete every record on the organization with the admin profile).

Edit (22 Sep 2017):

After bumping to this issue again after couple of months, I decided to file a Case for this issue.

The "Considerations for Setting Up Enhanced Email" documentation apparently specifies this:

With Enhanced Email, emails sent from Salesforce are saved as both EmailMessage records and Task records. However, only the EmailMessage record is shown on the email detail page in the UI.

  • Only the sender can delete the Task and EmailMessage records. If the sender deletes the task, no one else—including the admin—can delete the remaining email.

  • If you want to save space by removing the email message, the sender has to delete it.

I've got a link with the recommended approach on how to delete the records (which is very unintuitive, to be honest): https://help.salesforce.com/articleView?id=Special-considerations-when-attempting-to-delete-EmailMessage-records&language=en_US&type=1

I've been informed that Salesforce is working on this issue, to make this mass delete an easier process.

0

This is the easiest way to do this. Open your Developer Console and press Ctrl+E.

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); 

If you have admin rights you should be able to run this anonymous code that runs in system content and will delete those records you want to delete. If you have more that 200 a suggest that you use a for loop.

  • As I said in my original post: I have the privileges, including the "Modify All Data" permission, but even running that delete doesn't delete the records. I get an error when using the Data Loader to delete the records, but I get no errors when using Apex. I've logged a case with Salesforce about this yesterday too. – Renato Oliveira Mar 10 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.