function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PRepakaPRepaka 

how to set Organization wide email addressId for visualforce email templates

hi

 

can u please tell me how to set  

setOrgWideEmailAddressId for visualforce email templates.

 

If i give like this it shows an error that Save error: Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setOrgWideEmailAddressId(String) 

 

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

email.setOrgWideEmailAddressId('0D2T000000000MH'); //For QA

email.setTemplateId(objEmailTemplate.Id);

email.setTargetObjectId(objContact.id);

email.setSaveAsActivity(true);

email.setWhatId(AppointmentId);

email.setSenderDisplayName('Scheduling');

Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

 

 

can u please help me.

earlino727earlino727
Maybe you should cerate a object of OrgWideEmailAddress like this:
OrgWideEmailAddress owa  =  [select id, Address,IsAllowAllProfiles from OrgWideEmailAddress where Address = 'noreply@smeaddr.com'];

Then use the ID attribute for this OrgWideEmailObject

email.setOrgWideEmailAddressId(owa.Id); //For QA


 My guess is that it may not like the address literal string you used within the method parameter list because i use the same setup and have no problems.

However you may get an exception error because you are trying to use both a seSenderDisplayName method  - which uses the email Template name - and setOrgWideEMailAddress method. Use either one or the other. Here is the error messgae I got when using both:

SendEmail failed. First exception on row 0; first error: DUPLICATE_SENDER_DISPLAY_NAME, When an Org-Wide Email Address ID is specified, a sender display name may not be specified.: