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
Ivan-mIvan-m 

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');