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
NinoJoseNinoJose 

VisualForce Email Template not resolving when send from Case Milestone Action via field update

I am  currently developing an email notification triggered using case milestone warning and violation. Since we have a complicated recipients list based on case queue, I decided to do a field-update on the same case milestone warning and violation and created a trigger and a class that includes an asynchronous method that will handle the constructions of email objects and sending of email notification.

 

Everything works ok but emails we are receiving didn't resolves merge field values (only name and created date shows). When you manually update the case record the merge fields shows up fine same when you test the visualforce email template.

 

Since I'm using VF email template I tried to use custom controllers but alas worsen the issue as the email is not anymore sending.

 

I'd like to ask the community if this is something you also encountered before and what solution have you implemented? 

crop1645crop1645

Nino -- I had these issues myself. I looked in my code where I made notes to myself -- perhaps these will help:

 

//  templateId   must be ID of an Email template
//  targetObjId must be a Contact Id -- also used in merge fields of template recipient.xxxx
//  whatId    must be an SObject that is used in the merge fields of the template relatedTo.xxxx
//  fromId    if non null, use current user, otherwise, use this ID (most likely an org wide no reply id)
//  bcc      not permitted when using template

 

 

// -- fragment of code to prepare for sendEmail(..)

email.setToAddresses(toRecipients);
email.setCcAddresses(ccRecipients);
email.setTargetObjectId(targetObjId);
email.setWhatId(whatId);
email.setorgWideEmailAddressId(orgWideEmailId);
email.setTemplateId(templateId);

 

 You also need a relatedToType= value in your VF template <messaging:emailTemplate> component that is bound by SFDC to the SObject that is the primary merge field object (in your scenario - 'Case')

 

My experience is that if you violate one of the SFDC email rules, you will not get what you want so review the documentation in the APEX and VF guides carefully

 

NinoJoseNinoJose

Thanks Eric for the comment. I have put in a ticket from Salesforce for this.

 

The thing is the same approach is working for standard time-based workflow but not in case milestone.

 

I'll update this thread when I get the answer with sample codes. :-D