+ Start a Discussion
Vaibhav SuleVaibhav Sule 

Test Classes - assignment error "unexpected token '='"

Hello, I am a complete noob to salesforce. I am trying to test the InboundEmailHandler, and I wrote the following test class:

@IsTest
private class MMmeetingemailTest
{
    Messaging.InboundEmail email1 = new Messaging.InboundEmail();
    Messaging.InboundEnvelope env1 = new Messaging.InboundEnvelope();
    
    // Create the email body
    email1.plainTextBody = 'This should become a note';
    email1.fromAddress = 'test@test.com';
    string contactEmail  = 'jsmith@salesforce.com';
    email1.subject = 'a01O000000ZW5mo';
    MMmeetingemail mmemail = new MMmeetingemail();
    
    Test.startTest();
    Messaging.InboundEmailResult result = mmemail.handleInboundEmail(email1,env1);
    Test.stopTest();    
    System.assert (result.success , 'InboundEmailResult returned a failure message');    
}

However, I keep getting the following error: "unexpected token: '=' " for the line " email1.plainTextBody = 'This should become a note'; "
I don't understand what is incorrect here, since I am simply trying to assign a value to a valid object property.

Any help is appreciated.
Thanks!
 
Best Answer chosen by Vaibhav Sule
Anoop yadavAnoop yadav
Hi,
Try with the below code.
@IsTest
private class MMmeetingemailTest {

static testMethod void testMethod(){
    Messaging.InboundEmail email1 = new Messaging.InboundEmail();
    Messaging.InboundEnvelope env1 = new Messaging.InboundEnvelope();
    
    // Create the email body
    email1.plainTextBody = 'This should become a note';
    email1.fromAddress = 'test@test.com';
    string contactEmail  = 'jsmith@salesforce.com';
    email1.subject = 'a01O000000ZW5mo';
    MMmeetingemail mmemail = new MMmeetingemail();
    
    Test.startTest();
    Messaging.InboundEmailResult result = mmemail.handleInboundEmail(email1,env1);
    Test.stopTest();    
    System.assert (result.success , 'InboundEmailResult returned a failure message');    

	}
}
For more see the below links.
https://developer.salesforce.com/forums/ForumsMain?id=906F000000091VBIAY
http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/
 

All Answers

Anoop yadavAnoop yadav
Hi,
Try with the below code.
@IsTest
private class MMmeetingemailTest {

static testMethod void testMethod(){
    Messaging.InboundEmail email1 = new Messaging.InboundEmail();
    Messaging.InboundEnvelope env1 = new Messaging.InboundEnvelope();
    
    // Create the email body
    email1.plainTextBody = 'This should become a note';
    email1.fromAddress = 'test@test.com';
    string contactEmail  = 'jsmith@salesforce.com';
    email1.subject = 'a01O000000ZW5mo';
    MMmeetingemail mmemail = new MMmeetingemail();
    
    Test.startTest();
    Messaging.InboundEmailResult result = mmemail.handleInboundEmail(email1,env1);
    Test.stopTest();    
    System.assert (result.success , 'InboundEmailResult returned a failure message');    

	}
}
For more see the below links.
https://developer.salesforce.com/forums/ForumsMain?id=906F000000091VBIAY
http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/
 
This was selected as the best answer
Vaibhav SuleVaibhav Sule
Thanks a lot Anoop. This worked for me.