I have written an Email Service which goes like this :
global class myHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
EmailMessage emailMsg = new EmailMessage();
emailMsg.RelatedToId = *CUSTOM OBJECT RECORD ID*;
emailMsg.Subject = 'Test Subject';
emailMsg.fromAddress = *MY EMAIL ADDRESS*;
emailMsg.htmlBody = 'HTML';
emailMsg.fromName = 'From Name';
emailMsg.Incoming = true;
INSERT emailMsg;
system.debug('emailid####' + emailMsg.Id);
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
return result;
}
}
The Inbound email is created successfully and gets related to the Custom object Record, but I am unable to open the Email Message. It gives me error message when I am trying to open it using its record id:
Insufficient Privileges You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. For more information, see Insufficient Privileges Errors.
However when I run the Email Message creation logic in the above code using Developer Console, the Inbound Email Message is created and am able to view it successfully!
MODIFICATION TO THE ABOVE QUESTION
Just found that only the User who has created the Email Message has permission to view, not even other System Admins can view it.
Is there any way we can by pass this scenario?