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
pearlbearpearlbear 

Test class for a trigger

Hi there, I've written a trigger that sends an email based upon a new opportunity. Trigger works great. Now for the test classes. I've got this test class:

public class testEmailTrigger {
	//This class is simply to test the SendEmailTrigger trigger
	
	//Test Method
	static testMethod void testEmail {
		//Insert a record into the right table to test
		//In this case, the table is Opportunity

		Opportunity o = new Opportunity ();
		o.Amount='100';
		o.CloseDate = System.Today();
		o.Description = 'TEST';
		
		//Start the test
		test.startTest();
		insert o;
		test.stopTest();
	}

}

It complains at the line "Opportunity o = new Opportunity(); with the error "unexpected token Opportunity." What am I doing wrong?

Best Answer chosen by Admin (Salesforce Developers) 
DTCFDTCF

 

Your method declaration is wrong:

 

static testMethod void testEmail() {

 

You need the parentheses after testEmail. Also, you'll have a problem trying to set amount = '100', it will give you illegal assignment from String to Decimal.

All Answers

DTCFDTCF

 

Your method declaration is wrong:

 

static testMethod void testEmail() {

 

You need the parentheses after testEmail. Also, you'll have a problem trying to set amount = '100', it will give you illegal assignment from String to Decimal.

This was selected as the best answer
MikeGillMikeGill
Do you have a test class which creates accounts as this needs to be specified too?
pearlbearpearlbear

Actually, this trigger is for accounts/contacts that already exist.

 

Thanks!