You need to sign in to do that
Don't have an account?
How to attach additional variables to Email template?
I'm using this template to send Username and password to user:
Dear {!Contact.FirstName},
Your {!Organization.Name} Customer Portal login and password information is below.
Thank you,
{!Organization.Name} Customer Support
Out of the box salesforce functionality somehow adds Username: xxxx Password:yyyy strings to the end of template. But, I can't find how I can do that? Methods setPlainTextBody() and setHTMLBody are not allowed when I use email template.
Here is shrd code snipplet. I need attach Username and password to the bottom, but how?:
Id templateId = [select et.Id from EmailTemplate et where et.name = 'Customer Portal: Customer Portal New User Login Information (SAMPLE)' LIMIT 1].Id;
String[] toAddresses;
String password;
Messaging.SingleEmailMessage mail;
password = System.resetPassword(cpUser.Id, false).getPassword();
System.debug('New password:'+password);
//Send email notification
toAddresses = new String[] {cpUser.email};
mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.setTemplateId(templateId);
mail.setTargetObjectId(cpUser.contact.Id);
//This part doesn't work for sure =)
mail.setHtmlBody('Username:'+cpUser.Username+' Passord:'+password);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
System.debug('Email has been sent');