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? Jul 8 at 20:49
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.

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.