+ Start a Discussion
AKallAKall 

inbound email testing

Hello,

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 salesforce.com.
    */
   
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
       
     //run process
         ID rec = null;  
        SalesOPS_Handler.createTask(email.subject.trim(),email.plainTextBody,rec);
                    
        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 = 'user@acme.com';


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

aalbertaalbert

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.