+ Start a Discussion
Dr. Thomas MillerDr. Thomas Miller 

Trailhead: Subscribe to Change Events Using an Apex Trigger

Hi,
my challenge when doing the above mentioned module fails with the following error:

"The test method doesn’t insert an opportunity with the correct fields. Double check the Name, StageName, and CloseDate and try again."

The requirement is as follows:
In the test method, create an opportunity with the following fields.
Name: 'Sell 100 Widgets'
StageName: 'Prospecting'
CloseDate: Date.today().addMonths(3)


And the code is this:
    Opportunity opp =  new Opportunity(Name='Sell 100 Widgets',
           CloseDate=System.Date.today().addMonths(3),
           StageName='Prospecting');
    insert opp;


Any idea what could be wrong?

 
Best Answer chosen by Dr. Thomas Miller
Alain CabonAlain Cabon
@Dr. Thomas Miller

You code is totally correct but ... the script of the robot wanted until recently:  event.isWon == true

https://developer.salesforce.com/forums/ForumsMain?id=9062I000000IJoxQAG

(... while the documentation clearly says that you must be always "concise" )

It seems that the check by the robot is done for this module on the content of the code directly and not by a real test of an update like before.

Many questions on the forums about this terrible wrong check (that works without == true of course).

All Answers

Alain CabonAlain Cabon
@Dr. Thomas Miller

You code is totally correct but ... the script of the robot wanted until recently:  event.isWon == true

https://developer.salesforce.com/forums/ForumsMain?id=9062I000000IJoxQAG

(... while the documentation clearly says that you must be always "concise" )

It seems that the check by the robot is done for this module on the content of the code directly and not by a real test of an update like before.

Many questions on the forums about this terrible wrong check (that works without == true of course).
This was selected as the best answer
Dr. Thomas MillerDr. Thomas Miller
@Alain Cabon

After you indicated that it might be the robot expecting specific code I tried some stuff and copied from other blog entries.
At the end i found that replacing

System.Date.today().addMonths(3)
by
Date.today().addMonths(3)

did the trick. Unbelievable dumb challenge checking!
Alain CabonAlain Cabon
Thanks for your useful feedback.

There are other restricted method calls to pass the challenge as you mention (unbelievable). 

Enough to discourage some people with coding in Apex.