I have 3 custom objects in my salesforce org that are involved in a process builder. The process builder is invoked by creation of or changes to Commodity__c records. The process builder is outlined below:

Create Inspection Process builder

This process builder fires 2 different flows and sends the triggering commodity__c id into the flow. For the purpose of this question, I am going to focus on the second action. This action will fire if the Species__c field is Clementine, Lemon, Orange, or Tangelo. The flow that is fired looks like this:

Citrus Flow

This flow will create a Citrus_Inspections__c object related to the triggering Commodity__c record, and with a certain record type depending on the triggering Commodity__c's Species__c value. Then, once the Citrus_Inspections__c record is created, we create a Youreka form (disco__form__c) with a specific template based on the triggering commodity__c's Species__c value (Clementine, Tangelo, Orange, or Lemon). Finally, once the form record is assigned properly, it is created with a create form block (at the bottom of the flow but cut off by the screenshot).

In my test class, I am attempting to use a Test Data Factory to create Commodity__c records with a Species__c value of Clementine like so:

List<Commodity__c> commListClem = TestDataFactory.createSObjectList('Commodity__c',new Map<String,Object>{
        'Imported_Variety__c' => 'Test_Variety4',
        'Size__c' => 'Test_Size4',
        'Inspection_Request__c' => insReq.Id,
        'Inspect__c' => TRUE,
        'Species__c' => 'Clementine'

This call should create 10 Commodity__c records with the above field values, insert them and return the records back in a list. According to the above automation, the second action should also fire and the flow should create a Citrus__Inspections__c record related to the commodity__c record as well as a Youreka form record. However, everytime I execute this piece of code in my test class, it says the following:

FATAL_ERROR CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Inspection” process failed. Give your Salesforce admin these details. An error occurred when executing a flow interview.

This is referring to the Commodity__c records we are attempting to insert above. This only happens in a test class too. I executed that line of code in the anonymous apex window and it inserts perfectly fine. I also insert the same record and same data in the UI and it inserts perfectly fine (and the appropriate records are created by the flow). There are some validation rules that execute on the Citrus_Inspections__c record upon creation but those would fire any time I create the record, not just in the test class.

I also attempted to use plain DML statements in the test class (thinking it is an issue with the test data factory class) and the issue still persists. In addition, I also tried to run as a System Administrator using System.RunAs() and the issue still persists.

The issue only happens when trying to insert the above Commodity__c records. Above that block in my test class, I insert the following:

List<Commodity__c> commListColored = TestDataFactory.createSObjectList('Commodity__c',new Map<String,Object>{
        'Imported_Variety__c' => 'Test_Variety3',
        'Size__c' => 'Test_Size3',
        'Inspection_Request__c' => insReq.Id,
        'Inspect__c' => TRUE,
        'Species__c' => 'Grape'

This inserts a list of Grape commodities which fire the first action in the process builder. The action triggers a different flow but the automation follows the same principle. The record that gets created in the flow is a Grape_Inspection__c record but no Youreka form. These Commodity__c records insert perfectly fine.

I have also tested this in a developer sandbox as well as a partial copy sandbox. The issue persists in both environments.

Ultimately I am not sure what could be causing this. The class I am trying to test works fine, it is the test class won't pass due to not being able to create the test data needed to run the test. Has anybody had a similar issue where a process builder is only failing in a test context?

1 Answer 1


Figured out that the flow was trying to query data in Salesforce that was not created in the test. Once I figured out that the flow was trying to create a record with a null required field, I added DML at the top of my test to create the needed data and the test runs fine now!

You must log in to answer this question.

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