I'm facing with VisualForce Email Templates and I need to get the email body with rendered field in order to use it somewhere else.

This is an use case

I've got an email whit this body "Hello {!Account.Name}" and I want to use this body somewhere else with the rendered value of Account.Name, so that in the variable where I store the body I will get "Hello Fabio".

Is this possible?

Thanks in advance.

1 Answer 1


You need to use Savepoint, Try it like this

Savepoint sp = Database.setSavepoint();

List<Messaging.SingleEmailMessage> lstMails = new List<Messaging.SingleEmailMessage>();

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



String bodyTextWithMergeField = message.getBody();

// bodyTextWithMergeField will have all what you want.
  • I found a post on this web site where they were talking only about HTML Template, does it work for a VisualForce Template as well? Commented Feb 25, 2016 at 17:16

You must log in to answer this question.

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