I want a email template which will have text like this

Dear {contact.Name}

Thanks for approaching us for product {SR.product.Name}. we have reviewed your request and would like to correspond with you using {contact.Phone} .

SR is a custom object here.

Thanks, {user.Name} {user.title} {user.Department}

i want to call this template using a custom controller means these is a button on a VF page . on clicking this, it will call this template and send a email to some email address.

My question here is which email template i should use here (custom or VF template) and how to pass all these objects (Contact,SR,User) data to that template.

Any help regarding this would be great.



if you are using code (Messaging.singleEmailMessage) to send the email using the template just use an HTML / Plain text email template and set the targetObjectID to the contact and the whatID to the SR record.

  • Please note that the limit for single email messages is 2000 per day. – raffters Jun 4 '15 at 3:03
  • and what about user ?? how will I send the user id? – Sachin Kadian Jun 4 '15 at 7:31
  • @SachinKadian Use the global variable $User in your template to access values from the running user – cropredy Jun 5 '15 at 1:25

For your instance you need a vf template to be created. a page for your buttons logic and a controller. Your controller should contain Messaging.SingleEmailMessage().

your template should look like this> Dear {!relatedTo.Contact.Name} {!relatedTo.SR.Product.Name} and Thanks {!recipient.User.Name} {!recipient.User.Name}

Hope This answers your question.

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.