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

Help with user tests

Is there any workaround for creating users in a test method? I can't even compile code with a user insert statement and I get the error "DML not allowed on User".

How am I supposed to get test coverage on an insert trigger on User if I can't create a user in a test method?

I'm sure I can create an insert/update trigger and have code that ignores updates but that is a nasty hack.
Ron HessRon Hess
if you need to use User objects in your test method, you can query the existing user records and change their attributes in the test method to meet your needs. These changes will be discarded at the end of your test run.
The problem is that I want to test an insert trigger on User. Updating an existing user won't fire my trigger.
Ron HessRon Hess
I see, you are in a pickle, I can't think of an easy way to write a test method that will cause this trigger to fire.

I Suggest you add "after update" to your trigger, then you can at least write a test that will run it, inside your trigger you can determine if it is an insert or update and take different actions.