I'm trying to build a test class for me to move an Email Service class into Prod, but I'm getting this error.
Here is part of my code (The important bits)
Email Service Class
global class emailInbdounds implements Messaging.InboundEmailHandler{
global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,Messaging.InboundEnvelope env)
{
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
String myPlainText= '';
myPlainText =email.subject + '\n' + email.plainTextBody;
Test Class
@isTest(seeAlldata=True) private class testSendEmail {
@isTest static void testIdontKnow(){
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope envelope = new Messaging.InboundEnvelope();
email.subject = 'Test';
email.fromName = 'test test';
email.plainTextBody = 'Hello, this a test';
Messaging.InboundEmail.BinaryAttachment[] binaryAttachments = new Messaging.InboundEmail.BinaryAttachment[1];
Messaging.InboundEmail.BinaryAttachment binaryAttachment = new Messaging.InboundEmail.BinaryAttachment();
binaryAttachment.Filename = 'test.txt';
String algorithmName = 'HMacSHA1';
Blob b = Crypto.generateMac(algorithmName, Blob.valueOf('test'),Blob.valueOf('test_key'));
binaryAttachment.Body = b;
binaryAttachments[0] = binaryAttachment ;
email.binaryAttachments = binaryAttachments ;
envelope.fromAddress = '[email protected]';
emailInbdounds catcher = new emailInbdounds();
catcher.handleInboundEmail(email, envelope);
}
}
The error comes on the last line :
catcher.handleInboundEmail(email, envelope);
Based on my research , this error appears when the Data Type you are creating has not been initialized, but, the line prior to this one, already does that.
emailInbdounds catcher = new emailInbdounds();
handleInboundEmail
method. So, unless you post the code for this method, I doubt anyone would be able help you out.