0

i have created the email template visualforce template with merge field for opportunity. I am sending the mail using lwc. when I send the mail using the admin profile the mail is received into inbox. when when I log in as another user with a different profile, the mail is getting send but not receiving into the inbox.

EmailTemplate emailTemplateUWDocEmail=[SELECT Id, Name, DeveloperName FROM EmailTemplate where DeveloperName ='TemplateName'];
Opportunity oppRecord=[Select Id,Name,OwnerId,Account_Email_Formula__c From Opportunity where Id=:OpportunityId];

String[] toAddress = new String[] {oppRecord.Account_Email_Formula__c};

Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();

System.debug(UserInfo.getUserName()+UserInfo.getUserId());
 mail.setToAddresses(toAddress);
 mail.setTargetObjectId(UserInfo.getUserId());
 mail.setWhatId(oppRecord.Id);
 mail.setTemplateId(emailTemplateUWDocEmail.Id);
 mail.setSaveAsActivity(false);
 mail.setTreatBodiesAsTemplate(false);
 mail.setTreatTargetObjectAsRecipient(false);
 mail.setUseSignature(false);
 Messaging.SendEmailResult [] result=Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
1
  • How do you know the email is sent? Have you checked the email send log? Commented Jul 8, 2021 at 20:49

1 Answer 1

0

Enable the template access to the non-admin profile you are using.

This permission can be provided through profile or via permission sets. The setting can be found in Profile Settings -> System Permissions. Search for template and enable the relevant permissions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .