Tuesday, November 24, 2015

Salesforce: Test Class For Apex Email Service


This is the test class for the functionality Apex Email Service to create case from email, in Previous Article 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
@isTest
private class Test_CustomEmailCase {
 static testMethod void testEmailToCase() {
        
        Test.startTest();
   // Create a new email and envelope object
            Messaging.InboundEmail testEmail = new Messaging.InboundEmail();
            Messaging.InboundEnvelope envelope = new Messaging.InboundEnvelope();        
            testEmail.subject = 'The email subject';
            testEmail.plainTextBody = 'The email body';
            testEmail.fromAddress = 'test.testing@sometest.com';
   
   // Send the email
   CustomEmailCase TestEmailCase = new CustomEmailCase();
   // Invock the handler function
            CustomEmailCase.handleInboundEmail(testEmail, envelope);
   
   system.assertEquals([SELECT Type FROM Case LIMIT 1].Type, 'New');
  Test.stopTest();
    }
}
NB: This is for my future reference.

No comments:

Post a Comment