You need to sign in to do that
Don't have an account?
Apex test code failing with compile errors stating Unexpected Token.
Please help me with this test class.... Below is the code I am trying to get working... the class itself seems to work ok as it does decode incoming emails for me. But the problem is I am trying to get the test class portiion working and it simply will not compile for me. IF you look below where I have remarked out the lines that failed with //// 4 comment bars. each one of the below //// is giving the error unexpected token.... is there a solution for this... I need to build a test code for the email program shown at the Example Code Below.. Thanks in advance for any ideas.
//// Error: Compile Error: unexpected token: ',' at line etc....
//// Each line below that I have added //// gave the above error....
@IsTest
private class EmailDemoReceiveHandlerTests {
// Create a new email and envelope object
Messaging.InboundEmail email = new Messaging.InboundEmail();
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
// Set up your data if you need to
// Create the email body
//// email.plainTextBody = 'This should become a note';
//// email.fromAddress ='test@test.com';
String contactEmail = 'jsmith@salesforce.com';
//// email.ccAddresses = new String[] {'Jon Smith <' + contactEmail + '>'};
//// email.subject = 'Dummy Account Name 123';
EmailDemoReceive edr = new EmailDemoReceive();
Test.startTest();
Messaging.InboundEmailResult result = edr.handleInboundEmail(email, env);
Test.stopTest();
////System.assert (result.success, 'InboundEmailResult returned a failure message');
Account [] accDb = [select ID from Account where name=:email.subject];
System.assertEquals (1, accDb.size(),'Account was not inserted');
Contact [] cDb = [select firstname,lastname from Contact where email=:contactEmail];
System.assertEquals (1, cDb.size(),'Contact was not inserted!');
Contact c = CDb[0];
System.assertEquals ('Jon', c.firstName);
System.assertEquals ('Smith', c.LastName);
Note [] nDb = [select body from Note where ParentID=:accDb[0].id];
System.assertEquals (1,nDb.size(), 'A note should have been attached');
System.assertEquals (email.plainTextBody, nDb[0].body);
}
}
You need to create and enclose the code in a testMethod inside your test class
Use something like below
static testMethod void testInboundEmail() {
Don't forget to give Kudos if this solves your problem
All Answers
You need to create and enclose the code in a testMethod inside your test class
Use something like below
static testMethod void testInboundEmail() {
Don't forget to give Kudos if this solves your problem
if the class that I am running the test is named "EmailReceiveDemo" then should your term testinboundEmail be named "EmailReceiveDemo" to match the class that is actually being tested.... or am I totally lost... or it does not matter.... Thanks
static testMethod void are keywords that you cannot change
testInboundEmail is some name that I gave and you can change it to fit your needs - but it doesn't have to match anything