+ Start a Discussion

Test method for custom controller involving inactive users...

Hello folks,


I've run into a bit of a challenge. I have this nice page and controller built that allows ours sales management to reassign leads that are owned by inactive reps (recently left the company).


My problem is with test coverage. I wrote up the test method for the controller and everything showed 100% coverage in sandboxes. When I deployed though, the test fails due to the dreaded MIXED_DML_OPERATION exception.


The setup for the test involves:


  1. Find an active user with the proper Role.
  2. Create a few leads with different criteria and assign them to that user.
  3. Insert the Leads.
  4. Deactivate the User so that the controller finds the new Leads in the query.

It's that last line, of course, that causes an issue. I'm well aware of the MIXED_DML problem, but I was hoping I could get around it in a test method. When the tests all passed in the Sandbox, I thought I was OK.


Any thoughts on how to get code coverage if I have to have Leads owned by a User that is inactive?