9

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

1 Answer 1

6

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.

4
  • Thats what I thought. I just have the habit of creating Unit testing for any testable business logic implemented - programmatic and declarative, including Validation Rules, Field Updates, required fields, unique fields, formula (sometime) and such. I know it is not enforced, but I consider good practice since programmatic features are not the only one that can break a deployment of existing features. Thanks @Peter
    – jpmonette
    Feb 26, 2015 at 11:09
  • Your dedication to testing is admirable and deserves great praise for making the Cloud a more predictable place! :-)
    – pchittum
    Feb 26, 2015 at 11:43
  • hello @pchittum, in 2023, is this answer still true? Or has there been any recent releases that already allows us to query and/or delete queued items via apex or any other kind of automation?
    – SamuelDev
    Jan 30, 2023 at 1:59
  • That's a good question @SamuelDev. I'm actually not sure. But if you find something I welcome you to come back and give a better answer! :-)
    – pchittum
    Feb 28, 2023 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .