I'm building a test class for a controller that consists of a method for sending email. I need to provide test data for that email method. The test code is-
List<String> listEmail = new List<String>();
listEmail.add('[email protected]');
listEmail.add('[email protected]');
List<Messaging.EmailFileAttachment> efa = new List<Messaging.EmailFileAttachment>();
efa.fileName='Unit Test Attachment'; //error is here
efa.Body=Blob.valueOf('Unit Test Attachment Body'); //error is here
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.ToAddresses = listEmail;
email.PlainTextBody = 'Testing Email';
email.FileAttachments = efa; //error is here
Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
When I assign efa to email.FileAttachments, I receive this error- Variable does not exist: fileName
And if i comment fileName assignment then this error- Variable does not exist: Body
Please guide me as to what are the correct attributes?
Thanks in advance!