Tests, Individual Account, Lead Converstion
Snippets from an email from Steve Andersen regarding tests, deploying and ways to write your code to avoid challenges with the individual account.
I've learned a bunch over the last 2 weeks and I
wanted to pass it on.
If you have a setup with a Bucket account, like
Individual, and you've written Apex code that uses a Bucket account, you may
want to make some changes to how you test that code.
This all started as I was deploying code to a
client of mine and during the deploy to production I got an email about an
unhandled exception in a lead trigger. Turned out that while I was deploying
code someone filled out a form on the website and a lead was created. That lead
was auto-converted via a trigger we have, but was unable to complete because it
couldn't get exclusive access to the Individual account.
Why couldn't it? Because during a deploy, all
your tests run. And a whole lot of my tests expect and use the Individual
account. So, when my lead conversion test was running, it was locking up the
individual account for some seconds, and if production tried to edit that
account, there was a conflict, causing the form submission to fail.
We figured this out with help from
salesforce.com dev support. And I've spent quite a while changing all my tests
so that when the tests run they don't rely on an Individual account, but use a
testing individual account that is created in each test.
Do you have this problem? Here's an easy way to
find out. In a sandbox get rid of your individual account by changing it's name
or some other way to make it invisible to your code. Run all tests. Do they
pass without the individual account? If they don't, your tests are relying on
production data which can cause you problems. The greatest risk in my code is
around lead conversion. Salesforce lead conversion will update the bucket
account and we have to blank out some fields, so we have to update it in most
cases. If you are testing against live data this is what will lock things up in
your production environment.
If you have any questions about what this means
to you, ask away, I'm happy to help out.

