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
nil_von_9wonil_von_9wo 

Problem with Force.com Cookbook: Chapter 4: testLeadDupPreventer doesn't work

Currently continuing to work through the cookbook. There is a rather long test class from page 155 to 159 which doesn't work.I've discovered at least two errors which I don't know how to fix.

 

First, there is a recurrent error with the statement:

 

 

System.assert(e.getDmlFields(0)[0] == 'Email');

  

This results in:

 

Save Error: Comparison arguments must be compatible types: Schema.SObjectField, String

 

If I comment out these lines (which, to be honest, I don't understand how they are helping the testing), I discover there is another error. The second error occurs during the test to "Make sure that bulk lead duplication prevention works on insert."

  

 

System.assert(e.getNumDml() == 2);

 

 turns out to be false because the value of e.getNumDml() is actually 3.

 

While I could change this value to make the test pass, again, I don't really understand how this test is working, so just arbitrarily changing the value would seem to negate the value of the test, as perhaps this reflects other code being incorrect.

  

 

Can anyone explain how to fix either of these problems?

 

Or better yet, explain what each of these asserts is [supposed to be] doing:

 

 

System.assert(e.getNumDml() == 2); System.assert(e.getDmlIndex(0) == 1); System.assert(e.getDmlFields(0).size() == 1); System.assert(e.getDmlFields(0)[0] == 'Email'); System.assert(e.getDmlMessage(0).indexOf('A lead with this email address already exists.') > -1);

 

...o I can understand how and why this test works...