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
goodankit@yahoo.comgoodankit@yahoo.com 

How to write Email template in test class

Best Answer chosen by Admin (Salesforce Developers) 
Vinita_SFDCVinita_SFDC

Hello,

 

You can create an email template in a test class as we create in any apex class like:

 

EmailTemplate e = new EmailTemplate (developerName = 'test', FolderId = 'Give Id Of Email Folder', TemplateType= 'Text', Name = 'test'); // plus any other fields that you want to set

insert e;
 
Best way to create a custom email template is to create visualforce email templates. Please note that you can not sent emails from test calss.

All Answers

Vinita_SFDCVinita_SFDC

Hello,

 

You can create an email template in a test class as we create in any apex class like:

 

EmailTemplate e = new EmailTemplate (developerName = 'test', FolderId = 'Give Id Of Email Folder', TemplateType= 'Text', Name = 'test'); // plus any other fields that you want to set

insert e;
 
Best way to create a custom email template is to create visualforce email templates. Please note that you can not sent emails from test calss.
This was selected as the best answer
goodankit@yahoo.comgoodankit@yahoo.com
thx ..lot , how wil we get folderId of our email folder ?
Vinita_SFDCVinita_SFDC

Hello,

 

It is the ID of the folder that contains the template. Probably optional, refer the following link for better example:

 

http://salesforce.stackexchange.com/questions/12395/how-can-email-template-be-created-in-unit-tests

Charles dBCharles dB
Folder is not optional => folderId = userInfo.getUserId() is the easiest => as explained in the link posted by @Vinita_SFDC http://salesforce.stackexchange.com/questions/12395/how-can-email-template-be-created-in-unit-tests