1

Where Can I set the permissions for this object? I can see the record as an admin, because of Modify All permission. As a sales user, I can see only the records which were created by me. How to extend the visibility of EmailMessage records? I couldn't find this object on OWD objects list.

enter image description here

0

Determine the current access with the help of UserRecordAccess object. In general, you need to enable Email to case in the Org to have access to EmailMessage Object

SELECT RecordId, HasReadAccess, HasTransferAccess, MaxAccessLevel
 FROM UserRecordAccess
 WHERE UserId = [single ID]
 AND RecordId = [single ID]      //or Record IN [list of IDs]

Create an EmailMessage record anonymously (As an admin and affected user. For affected user, you can determine access using System.runAs()in a test class) to confirm if you are seeing the same error. See sample code below

If you are running into the same issue, you need to check if you have Enhanced Email enabled

I also suggest verifing the following permissions on the affected user's profile:

'Send Email' permission is enabled.

User 'Read' access on Accounts & User has 'Read' access on Contacts

EmailMessage emailMessage = new EmailMessage();
emailMessage.status = '3'; // email was sent
emailMessage.relatedToId = '006B0000003weZGIAY'; // related to record e.g. an opportunity
emailMessage.fromAddress = 'sender@example.com'; // from address
emailMessage.fromName = 'Dan Perkins'; // from name
emailMessage.subject = 'This is the Subject!'; // email subject
emailMessage.htmlBody = '<html><body><b>Hello</b></body></html>'; // email body
// Contact, Lead or User Ids of recipients
String[] toIds = new String[]{'003B000000AxcEjIAJ'}; 
emailMessage.toIds = toIds;
// additional recipients who don’t have a corresponding contact, lead or user id in the Salesforce org (optional)
emailMessage.toAddress = 'emailnotinsalesforce@toexample.com, anotherone@toexample.com';
insert emailMessage; // insert
 
// Add Email Message Relation for id of the sender
EmailMessageRelation emr = new EmailMessageRelation();
emr.emailMessageId = emailMessage.id;
emr.relationId = '005B0000003qHvOIAU'; // user id of the sender
emr.relationType = 'FromAddress';
insert emr;

If none of the above helps, please create a support case

3
  • Hi @Anudeep, my user has access to see the EmailMessage records which were created by him, but not the one which was created by another user. I think it's about visibility issue. I just can't find the place where I can see the sharing model of EmailMessage, can you help ? Dec 14 '20 at 12:32
  • Just updated the question Dec 14 '20 at 13:25
  • As EmailMessage has no visibility settings in the profile, I would assume it's visibility is controlled by its parent. Can you execute this query and check if the sales user has access to the ParentId Select Id, ParentId, ActivityId, Subject, IsDeleted FROM EmailMessage WHERE Id = '02s1n00000VGtPMAA1' Dec 15 '20 at 13:09
0

Just resolved the issue by changing the EmailMessage object "Status" field from '5' (Draft) to '3' (Sent). And the record now is visible! Not sure why drafts are visible only to their creators.

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.