Find your content:

Search form

You are here

Inbound Email Test Error - 'Invalid type: EmailDemoReceive'

 
Share

I've successfully set up an inbound email to load a particular set of data, however when writing the test case i'm getting the invalid type error on the following line:

EmailDemoReceive edr = new EmailDemoReceive();

Any ideas?


Attribution to: paul

Possible Suggestion/Solution #1

a bit of googling... Call the InboundEmail class rather than EmailDemoReceive


Attribution to: paul

Possible Suggestion/Solution #2

This is my implemented class


global class SFA_EmailServiceHandlerUtility implements Messaging.InboundEmailHandler{

//Apex classes that implement the Messaging.InboundEmailHandler interface
//Inbound email handler to intercept the email and start the next batch
//This class compares the body string passed in the Email Handler Utility Class  and start the next job
//This class contains business logic for chaining of two Jobs ,Compare the strings and start the next job based on string passed in the Email_Handler Class.

      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope envelope){
        system.debug('Start of handleInboundEmail method');
        if (email.plainTextBody==Label.SFA_BatchStartOrder){
              // create the instance of second batch class
              String query = 'Select Winner__c, Loser__c, Processed__c, Error__c from Address_Merge__c' 
                     + ' where Processed__c = false and Error__c = false';
              SFA_AddressMergeBatch addMerge = new SFA_AddressMergeBatch(query);
              Id batchprocessId = Database.executeBatch(addMerge);
           }
      Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
      system.debug('End of handleInboundEmail method');
      return result;
    }
}

This is my test class for same


@IsTest(SeeAllData=true)

private class SFA_TestEmailServiceHandlerUtility {

//Test case 1-Positive Scenario 

/*Aim:  Test whether second batch is triggered if body has correct specified message
*/

private  static testMethod void testEmailHandler(){

    // Create a new email and envelope object
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

    //Set up the Test data

     Account winAccount = new Account();
     winAccount.MDM_ID__c='5011';
     winAccount.Name ='TestFirst TestSecond';
     insert winAccount;

    Address__c winAddress = new Address__c();
    winAddress.HCA_HCP__c=winAccount.Id;
    winAddress.AMDM_Address_ID__c ='4011';
    winAddress.Address_Line_1__c='Win Address Line 1';
    winAddress.city__c='LA';
    winAddress.zip_code__c=9090;
    insert winAddress;

    Address__c loseAddress = new Address__c();
    loseAddress.HCA_HCP__c=winAccount.Id;
    loseAddress.AMDM_Address_ID__c ='5011';
    loseAddress.Address_Line_1__c='Lose Address Line 1';
    loseAddress.city__c='NY';
    loseAddress.zip_code__c=9090;
    insert loseAddress;

    Address_Merge__c addMerg= new Address_Merge__c ();
    addMerg.winner__c ='4011';
    addMerg.loser__c ='5011';
    insert addMerg;


        // Create the email body
        email.plainTextBody = Label.SFA_BatchStartOrder;
        email.fromAddress =SFA_EmailServiceAddress__c.getInstance('SFA_EmailServiceHandler').EmailAddress__c;
        email.subject = 'Test Batch';

        SFA_EmailServiceHandlerUtility edr = new SFA_EmailServiceHandlerUtility();
        edr.handleInboundEmail(email,env); 

        Test.startTest();
        Messaging.InboundEmailResult result = edr.handleInboundEmail(email, env);
        System.assertEquals(result.success, true);
        Test.stopTest();

        List <Address__c> reparentedAddress = [SELECT id  FROM Address__c where id=:loseAddress.id];//Verify that the loser Id record  is deleted

        System.AssertEquals(0,reparentedAddress.Size());  //Assert whether the loser address is deleted .This confirms batch ran

}

}

watch clearly the way i have instantiated the email handler class .

Hence We must instantiate the email handler first then pass the envelop and email in handleinbound email method


Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1842

My Block Status

My Block Content