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
dhoechstdhoechst 

Best Practices for Trigger Testing and Workflow Rules

I've got a workflow that runs when a boolean field is set to true. The workflow sends an outbound message and does a field update to the boolean to false.

 

I've got a trigger that updates that boolean field to true. My problem is that when I write the test, it fails in the assertion because the boolean has been reset to false by the workflow. How can I do an assertion here? I'm good on code coverage and I know that the trigger is working, but I really want someway to do the assertion. Does anybody have any ideas?

WillNWillN

Might be overkill, but you could add a field to your object (another boolean) which gets set to true by the trigger (and only the trigger).  Write your assertion based on that field.

dhoechstdhoechst

The thought had occurred to me. Just thought of another idea. I could do a Test.isRunningTest() in the trigger and update some other field only when tests are running. Then I could assert on that one...