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

inbound email testing


I'm a beginner that wrote a simple email handler class that invokes another class. I am having a hard time getting my test class to work. I have pasted both below. Thanks for any suggestions.


The email Handler:


global class licIDReqCatcher implements Messaging.InboundEmailHandler{
    /*This class receives emails pertaining to License ID requests that are
      are forwarded from the SOA inbox, and creates a task for SOA to begin
      contract tracking in
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
     //run process
         ID rec = null;  
        return result;


The Test:


public class licIDReqCatcherTest {
    public static testMethod void test_licIDReqCatcher(){
        System.debug('Im starting a method');
        // Create a new email, envelope object and Attachment
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        email.subject = 'test';
        email.plainTextBody = 'Hello, this a test email body. for testing purposes only. Bye';
        env.fromAddress = '';

        // setup controller object
        licIDReqCatcher catcher = new licIDReqCatcher();
        catcher.handleInboundEmail(email, env);


What is not working in your code? Is it not compiling? Or it compiles and executes, but nothing happens?

Is your Email Service setup to receive from this address?

Your test method should probably verify that the data is created or properly processed by the inbound email handler too after you send the email.