I need to write a testmethod that checks if the triggerHandler works fine. I have a Trigger on Users, a TriggerHandler that calls up a class and one of its methods, and a testclass.

But how do I check if a triggerHandler works correctly, what is the right approach?

Thank you in advance!

  • To get a specific answer you would need to share some code - have you written a test class before? – Girbot Sep 29 '17 at 18:17

Best practice involves encapsulating your code. To put that another way, if you have written a triggerHandler Class, you should create a corresponding triggerHandler_test Class.

That triggerHandler_test Class should test the triggerHandler independently of the trigger itself. This is how you can encapsulate your trigger handler code and segregate it from the trigger.

Chances are, a trigger handler is going to have a list or a map (or both) as an input parameter. Your unit test will need to setup that test data. Naturally you will want that test data to look like it came from a trigger.

| improve this answer | |

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