I am somewhat vexed by this and I would like a little guidance.

I have a flow that fires on record create or update and I have written an Apex test class to test that it works as intended. I have set up this flow to run asynchronously.

When my logic is in the Run Immediately path, everything's fine and my test passes. Once I change the flow to have all my logic Run Asynchronously, however, the test no longer passes.

Based on this, there's someway to use a mock callout the way one would test HTTP requests but I am not clear on how to approach that when trying to callout an asynchronous flow explicitly in Apex.

For clarity, here's an idea of what my Apex test class looks like. I was under the impression that Test.stopTest() would cause all asynchronous flows to run in sync and then process once it is done, but this does not seem to be the case:

public class test_async {
    static void setup() {
        Account acc = new Account();
        acc.Name = 'Test';
        acc.Custom_Date_Field__c = Date.newInstance(2022,01,15);
        insert acc;            
    static testMethod void testFlow() {
        Account acc = [SELECT Id FROM Account WHERE Name = 'Test' LIMIT 1];

        Custom_Object__c o = new Custom_Object__c(Account__c=acc.Id,Date_Field__c=Date.newInstance(2022,09,20));
        insert o;
        Account updatedAccount = [SELECT Id,Custom_Date_Field__c FROM Account WHERE Id = :acc.Id LIMIT 1];
        System.debug('Account: '+updatedAccount);


Again, this passes when the logic in the flow runs immediately but not when it runs asynchronously. What am I missing? Is this just an Apex tests Apex situation?


1 Answer 1


In continuation to this recent post, I've checked with the concerned Salesforce Product team and got feedback that Asynchronous paths and waits cannot currently be tested in apex tests.

I will check if the documentation can be updated to reflect this info and update this thread.Thanks!

You must log in to answer this question.

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