[SalesForce] Querying Time-based Workflow Queue

Is it possible to query the content of the Time-based Workflow Queue from an Apex unit test to assess that a specific Workflow Rule has been executed and added a new item to the queue? I didn't see anything alike in the documentation, but wish it could be possible to improve testing and stability overtime.

Thanks

Best Answer

Apex tests are for testing Apex. They are not designed to test for declarative features.

That being said, I agree with the desire to do so. Why not write a test that ensures that functionality behaves in a predictable way, regardless of it being done via point-and-click or via code.

Back to your question though.

The time based workflow queue is not queryable via Apex, or the API.

There is a relatively new feature called the Event Log Monitoring. This is a paid feature. If you're wanting to monitor use or modification of a workflow rule to monitor changes in your org, this may give some ability to do what you want. But this isn't a write-a-test-get-in-sync-result fashion. The event log is meant for a periodic delivery model (daily, I think), to then write reports on the data.

The object that stores event log is called EventLogFile and is visible in API 29 and later.

So if you really want to write a test in Apex to assert successful execution of async workflow time triggers, sorry. No luck there. But if this is about preventing the rule from changing...you can look into the EventLogFile feature.

Related Topic