We created a trigger and test class: when a new record under Keyword object is created, we want an email notification sends out automatically to record owner and confirm we receive his keyword request. But we got error message for test class, we don't know how to reference folderId for email template and could not find information that makes it work. Please help.
Error Message System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [FolderId]: [FolderId]
@isTest
public class SendKRNotificationTest
{
static testMethod void SendEmail()
{
Test.StartTest();
EmailTemplate et = new EmailTemplate (developerName = 'test', TemplateType= 'text', Name = 'test');
insert et;
Keyword__c k = new Keyword__c();
insert k;
Test.StopTest();
}
}
TRIGGER:
trigger SendKRNotification on keyword__c (after insert) {
keyword__c keyword = trigger.new[0];
String[] toAddresses = new String[] {keyword.email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(keyword.OwnerID);
mail.setSenderDisplayName('Admin');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
{
EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Keyword_Request_Confirmation'];
mail.setTemplateId(et.id);
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}