The below code runs fine with Salesforce internal users, but throws an exception while run by Site Guest User.

List<Messaging.SingleEmailMessage > msgList = new List<Messaging.SingleEmailMessage>();
EmailTemplate template = [select Id from EmailTemplate where DeveloperName = 'Registration_Confirmation'];
System.debug('Debug Log for template'+template);
for(Digital_Entitlement__c thisDe : EntitlementList){
    Messaging.SingleEmailMessage emailMsg ;
    emailMsg = Messaging.renderStoredEmailTemplate(template.id, null, thisDe.Id);
    String[] recipients = new String[]{thisDe.Email_Address__c};
    //if(thisDe.Journal_Code__c.equalsIgnoreCase('XWP') || thisDe.Journal_Code__c.equalsIgnoreCase('XNW')){

The error is encountered during execution of this line :

emailMsg = Messaging.renderStoredEmailTemplate(template.id, null, thisDe.Id);

The error message is :

System.EmailTemplateRenderException: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: insufficient access rights on cross-reference id

Can anyone please help? I am not sure as to which permission to grant to the site guest user?

  • Is it a VF Email Template or a regular one?, Check that the Guest User has access to all the VF / Components / Classes that are required to send the email – Sergio Alcocer Feb 17 at 7:50
  • Yes @SergioAlcocer, it is a VF Template. How do I ensure that what all things needs to be made accessible to the site guest user in this case? The template in itself consists of the markup. – Shobhit Saxena Feb 17 at 8:05

Your Answer

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

Browse other questions tagged or ask your own question.