4

I had a VF page with a custom controller. The VF page simply shows how many leads were created by each salesperson in the following ways. Say, for Sales Associate A,

how many leads he created YTD how many leads he created in the last 6 months how many leads he created in the last 3 months how many leads he created this week how many leads he converted YTD how many leads he converted in the last 6 months how many leads he converted in the last 3 months how many leads he converted this week

As far as I know, trying to create test data is simply a nightmare. If I create any test data, all the leads would've been created today when the test is run. So I used the static resource (Test.loadData) because I could set the Created Date that way.

OK, at least I am able to put in created date other than today.

However, how do I set up converted Lead data? I cannot use the static resource to put in converted Lead data because it's expecting me to indicate the ConvertedAccountId which I don't have unless I set seeAllData to true.

As a result, I can only load lead data from static resource, but if I do any conversion, the converted date will always be set to today, so I am not really able to test very thoroughly.

Any ideas? As far as I know, ConvertedDate is not a writeable field.

Thanks a lot King

4

Here is a much better answer

Lead [] lList = (Lead[]) JSON.deserialize('[{"ConvertedDate" : "2005-01-01"}]',List<Lead>.class);

You use JSON.deserialize to create a test list of Leads. The deserialize ignores the restriction on setting unwriteable fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.