FlowTest defines tests for record-triggered, autolaunched, and Data Cloud-triggered flows. It supplies test inputs and expected outcomes so you can verify flow behavior and identify runtime failures before activation.
A flow test is a separate metadata component from the Flow being tested, not an activation setting. Its inherited fullName identifies the test; flowApiName identifies the associated flow.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The test component's metadata identity, inherited from the base metadata type. This is distinct from the associated flow's API name. |
flowApiName |
Required. The API name of the Flow being tested. |
label |
Required. The display label of the test. |
flowTestFlowVersions.flowVersionNumber |
Records a flow version associated with the test. It does not instruct Salesforce to activate that version. |
testType |
Required. WithAssertion compares actual flow outcomes with user-defined expected outcomes. The exposed schema also includes WithoutAssertion, whose execution semantics are not documented. |
testPoints.elementApiName |
Required within a test point. The documented values are Start and Finish, not arbitrary flow-element names. |
testPoints.parameters.type |
Required within a parameter. Documented input types are InputTriggeringRecordInitial, InputTriggeringRecordUpdated, InputVariable, and ScheduledPath. |
testPoints.parameters.leftValueReference |
Required. Identifies the input being supplied. Triggering-record parameters require $Record; scheduled-path parameters require ScheduledPathApiName. |
testPoints.parameters.value |
Required. Supplies the parameter value using the FlowTestReferenceOrValue structure. |
testPoints.assertions.conditions |
Defines each assertion's checks. Each condition requires leftValueReference and operator, with rightValue supplying a comparison value where applicable. |
testPoints.assertions.errorMessage |
Custom diagnostic text shown in Flow Builder when an associated condition evaluates to false. |
flowTestDataSources |
Defines isolated-data sources for record-triggered and autolaunched flow tests. When dataSourceType is ApexClass, apexClass is required. |
isolatedObjectExternalKeys.objectType |
Required within an isolated-object declaration. Identifies the object whose test records are distinguished by the nested key fields. |
isolatedObjectExternalKeys.keyFields.fieldName |
Required within a key-field entry. Identifies a field used to distinguish unique test records. Lookup fields must not be used. |
Behavior and Constraints
Salesforce evaluates testPoints in their listed order. The documented test-point locations are Start and Finish. A condition can refer to a flow resource, but that does not make the resource's name a valid testPoints.elementApiName.
Start-point inputs
Parameters on the Start test point establish the triggering record, selected path, or flow input variables:
-
InputTriggeringRecordInitialrequiresleftValueReferenceto be exactly$Recordand supplies the initial record input. -
InputTriggeringRecordUpdatedalso requires exactly$Recordand supplies the updated record input. The parameter type, not a different resource name, distinguishes it from the initial record. -
ScheduledPathrequiresleftValueReferenceto be exactlyScheduledPathApiName. The parameter's value supplies the scheduled path to test. -
InputVariablesupplies a flow input variable identified byleftValueReference.
Assertions and failure results
An assertion is an expected-outcome check. If any condition evaluates to false, its assertion fails. If any assertion evaluates to false, the test run fails. Multiple conditions in one assertion therefore must all pass; they are not alternatives.
Within each condition, leftValueReference names the flow resource to evaluate, operator specifies the check, and rightValue supplies the comparison value where applicable. Documented operators include:
- Comparisons:
EqualTo,NotEqualTo,GreaterThan,GreaterThanOrEqualTo,LessThan, andLessThanOrEqualTo. - Text and membership checks:
Contains,StartsWith,EndsWith,In, andNotIn. - Blank, empty, and null checks:
IsBlank,IsEmpty, andIsNull. - Flow-oriented checks:
HasError,IsChanged,WasSelected,WasSet, andWasVisited.
The resource reference and operator together determine what an assertion verifies. Interpreting the test requires the associated flow's resources and logic, especially when conditions name variables, record fields, or flow elements.
An assertion's errorMessage is custom text displayed in Flow Builder when an associated condition fails. It is not a platform-generated runtime error message.
Values and isolated test data
Parameter values and assertion comparison values use FlowTestReferenceOrValue. It provides typed scalar elements such as booleanValue, dateValue, dateTimeValue, numberValue, stringValue, and timeValue, along with sobjectValue and jsonValue. The jsonValue element contains JSON for an isolated test-data record. elementReference is reserved for future use; it is not a documented way to reference a flow resource.
Isolated-data configuration is documented for record-triggered and autolaunched flow tests. Its settings have separate roles:
-
flowTestDataSourcesidentifies the source that supplies test data. FordataSourceTypeequal toApexClass,apexClassnames the Apex data-source class. -
isolatedObjectExternalKeysidentifies the objects and key fields used to distinguish unique records in that data. - Parameter values supply the test inputs, including isolated-record JSON where used.
The key-field declarations identify test records. They do not create fields or change a field's uniqueness settings. Do not use lookup fields as isolated-data key fields.
There are no additional access requirements specific to FlowTest.
Deployment and Retrieval
FlowTest components use the .flowtest suffix and are stored in the flowtests folder. In a package.xml manifest, select the component under the type name FlowTest. The member name identifies the test component, not the flow named by flowApiName. This type supports the * wildcard in the manifest.
The test's dependency scope comes from the references actually populated in it: the associated Flow, any Apex data-source class, and the object and field definitions used by isolated data. A test does not depend on every type merely because the schema permits that relationship.
flowTestFlowVersions records version associations through flowVersionNumber. Those associations are not activation instructions. Likewise, the test itself remains a separate component rather than an activation setting on the flow.
Relationships
The main relationship is the flow named by flowApiName. Isolated-data configuration can add dependencies on an Apex class and object and field definitions. Variables, record fields, and flow elements named inside assertions must also be interpreted in the context of the associated flow.
References
-
ApexClass:apexClasswithinflowTestDataSources. -
CustomField:fieldNamewithinisolatedObjectExternalKeys.keyFields. -
CustomObject:objectTypewithinisolatedObjectExternalKeys. -
Flow:flowApiName.
Documentation Inconsistencies
The exposed schema is broader than the published FlowTest behavior. It includes testType value WithoutAssertion, dataSourceType value AiGenerated, and flowTestDataSources.testDataJson. Their presence does not establish how tests without assertions execute or how test data is generated.
Mock-output configuration also has a naming and support discrepancy. The exposed schema uses testPoints.isUseMockOutput, while the published type definition spells it isUseMockOuput and marks it reserved for future use. The schema additionally exposes parameter type MockElementOutput and test-point element pathAfterMockOutput. These settings do not constitute a fully documented mocking contract.
Common Questions
How do I retrieve a FlowTest with package.xml?
Use FlowTest as the manifest type and the test component's name as the member. The type supports the * wildcard. Its metadata folder is flowtests, and its file suffix is .flowtest.
Is flowApiName the name of the flow test?
No. flowApiName identifies the associated flow. The test's inherited fullName identifies the test component. Flow-version associations do not activate the associated versions.
How do I configure a scheduled path in a flow test?
Add a parameter to the Start test point with type set to ScheduledPath and leftValueReference set to exactly ScheduledPathApiName. Supply the scheduled path in the parameter value.
Do multiple FlowTest assertion conditions use AND or OR?
They behave as an all-must-pass check: any false condition fails its assertion, and any false assertion fails the test run.
Can I use a lookup field as an isolated test-data key?
No. Lookup fields must not be used in isolatedObjectExternalKeys.keyFields. Those entries identify unique test records; they do not create fields or alter field uniqueness settings.