I'm trying to write a unit test to check whether or not an outbound message was triggered via a workflow. For instance, I have a class that will set a field on a contact record. The workflow rule is setup to evaluate the field on the contact and if it matches some criteria, it will queue an outbound message. I'm curious to see if there is a way to test if limits were invoked as a result of the workflow rule being kicked off. Kind of similar to how you can test email messages being sent. Perhaps they are the same limits?



No, there's nothing you can check as part of your test. The objects involved cannot be queried, and there's no per-transaction limit on outbound messages. There are only hourly limits as mentioned in the documentation, and unit tests don't count against this limit because the messages are never committed to the database.

  • +1 classic. I always go in with test mindset, but SF can make that difficult. Thanks for the response!
    – Brohan
    Nov 7 '18 at 19:52
  • @gNerb There are limits to number of active rules per object and per org, number of outbound messages per rule, and number of sent outbound messages per hour, and limits to how many times rules can run recursively, but there's no explicit limit to how many outbound messages can be queued per transaction. Having too many queued messages will result in delays or failures, but these cannot be detected in a test.
    – sfdcfox
    Nov 7 '18 at 19:58
  • you're probably right but I'd like to play around with it and test it myself to see what I can detect in a test.
    – gNerb
    Nov 7 '18 at 20:00
  • Yup you are correct, none of the available limits checks showed anything worth looking at.
    – gNerb
    Nov 7 '18 at 20:12
  • Thanks all. Ultimately, I was looking to see if a workflow rule criteria was met, and if that criteria was met: an outbound message would fire. So instead of testing to see if an outbound message was sent, I created a field update and asserted whether or not the field was set. If the field was set, that tells me the workflow criteria was true.
    – Brohan
    Nov 7 '18 at 21:51

An option is to test indirectly

  1. Set up your Workflow rule to do an outbound message AND create a Task
  2. In your test, verify that the Task was created.

It is often useful to create Tasks to memorialize that a Workflow or Process Builder executed, if for no other reason than provide an audit trail that can aid in diagnostics

You won't be able to test limits as sfdcfox pointed out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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