You need to sign in to do that
Don't have an account?
xNamelessonex
Email Service Class, works under sandbox environment, generates INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY in Production
I have the following Class which was created under a sandbox environment, following the tutorial from this guide https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com:
And the Test Class:
When I created the Email Service, the user for the Context User, under the Email address associated to the Email Service is a Super User, with full priviledges on the organization. It is the same user as the Email Service from the Sandbox. And the configuration of the Email service is the same. Is there any configuration I might be missing under the production environment which triggers the Error:
"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" When Inserting the Comment into Salesforce?
global class CaseCommentReply implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope envelope ) { Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); try { Id csId = Cases.getCaseIdFromEmailThreadId(email.subject.substringBetween('ref:', ':ref')); System.debug('CaseId Value'+ csId); if (csId != null) { String TextStrip = email.plainTextBody; CaseComment comment = new CaseComment(ParentId = csId,CommentBody = TextStrip.substringBefore('--Reply above this line--'),isPublished = true); insert comment; System.debug('The comment of the case with the Id '+comment.ParentId+ 'has been updated \n The text: \n'+comment.CommentBody); result.success = true; } } catch(Exception e) { System.debug('An exception ocurred while attempting to create a comment from Email '+e); System.debug('There were errors while processing the function'); result.success = false; } if (result.success == true) { System.debug('The function has processed correctly'); } return result; } }
And the Test Class:
@isTest public class CaseCommentReplyTest { static testMethod void TestEmailToComment() { Case testCase = new Case(); insert testCase; String caseId = testCase.Id; System.debug('Value of the case id'+caseId); string Case_ThreadID = '_' + UserInfo.getOrganizationId().left(4) + '0' + UserInfo.getOrganizationId().mid(11,4) + '._' + caseId.left(4) + '0' + caseId.mid(10,5); Messaging.InboundEmail email = new Messaging.InboundEmail(); Messaging.InboundEnvelope env = new Messaging.InboundEnvelope(); email.plainTextBody = 'Test'; email.subject = 'Re: Sandbox: Case. [ ref:'+Case_ThreadID+':ref ]'; Messaging.InboundEmail exceptionEmail = new Messaging.InboundEmail(); Test.startTest(); CaseCommentReply crep = new CaseCommentReply(); crep.handleInboundEmail(email,env); crep.handleInboundEmail(exceptionEmail, env); Test.stopTest(); } }
When I created the Email Service, the user for the Context User, under the Email address associated to the Email Service is a Super User, with full priviledges on the organization. It is the same user as the Email Service from the Sandbox. And the configuration of the Email service is the same. Is there any configuration I might be missing under the production environment which triggers the Error:
"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" When Inserting the Comment into Salesforce?
This is the line of code used to generate said ThreadId:
I do wonder will our BELOVED </sarcasm> overlords ever give us an official way to get the ThreadId from apex?