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
Becky Miller 15Becky Miller 15 

Test Script Help

I have this Test Class code and I am not sure what I am doing wrong to get the 2 errors.

isTest
private class EmailServiceExampleTest
{
    static testMethod void testUnsubscribe() 
    {
       // Create a new email and envelope object.    
       
       Messaging.InboundEmail email = new Messaging.InboundEmail() ;
       Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();
    
       // Create Test record.
       Contact cont = new Contact(firstName='john', lastName='smith', Email='test@test.com', HasOptedOutOfEmail=false);
       insert cont ;
       
       // Test with the subject that matches the unsubscribe statement.
       email.subject = 'Test Contact Email';
       email.plainTextBody = 'Test Contact Email';

       env.fromAddress = 'test@test.com';
       EmailServiceExample obj= new EmailServiceExample();
       obj.handleInboundEmail(email, env );



I am getting these 2 errors:
Line 20 - Invalid Type: EmailServiceExample
Line 21 - Variable does not exist: obj
 
Best Answer chosen by Becky Miller 15
Becky Miller 15Becky Miller 15
That fixed Line 20

Now Line 21
Method does not exist or incorrect signature: void InboundEmail(Messaging.InboundEmail, Messaging.InboundEnvelope) from the type EmailServiceExampleTest


@isTest
private class EmailServiceExampleTest
{
    static testMethod void testUnsubscribe() 
    {
       // Create a new email and envelope object.    
       
       Messaging.InboundEmail email = new Messaging.InboundEmail() ;
       Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();
    
       // Create Test record.
       Contact cont = new Contact(firstName='john', lastName='smith', Email='test@test.com', HasOptedOutOfEmail=false);
       insert cont ;
       
       // Test with the subject that matches the unsubscribe statement.
       email.subject = 'Test Contact Email';
       email.plainTextBody = 'Test Contact Email';

       env.fromAddress = 'test@test.com';
       EmailServiceExampleTest obj= new EmailServiceExampleTest();
       obj.InboundEmail(email, env );
                            
    }
     
}

All Answers

Neo NemNeo Nem
recheck your "EmailServiceExample" class name!!
Becky Miller 15Becky Miller 15
That fixed Line 20

Now Line 21
Method does not exist or incorrect signature: void InboundEmail(Messaging.InboundEmail, Messaging.InboundEnvelope) from the type EmailServiceExampleTest


@isTest
private class EmailServiceExampleTest
{
    static testMethod void testUnsubscribe() 
    {
       // Create a new email and envelope object.    
       
       Messaging.InboundEmail email = new Messaging.InboundEmail() ;
       Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();
    
       // Create Test record.
       Contact cont = new Contact(firstName='john', lastName='smith', Email='test@test.com', HasOptedOutOfEmail=false);
       insert cont ;
       
       // Test with the subject that matches the unsubscribe statement.
       email.subject = 'Test Contact Email';
       email.plainTextBody = 'Test Contact Email';

       env.fromAddress = 'test@test.com';
       EmailServiceExampleTest obj= new EmailServiceExampleTest();
       obj.InboundEmail(email, env );
                            
    }
     
}
This was selected as the best answer