Explanation of the error (in relation to the Flow
metadata type):
This Salesforce validation error that Gearset is surfacing is likely to occur specifically on the Flow
metadata type:
"Invalid element reference <xxx> not found for target"
.
In the use case we've investigated, the error occurred when a user tried to deploy a new event flow from a Git branch to a Salesforce org.
In this example referenced element (referred to as <xxx>
) within the validation error was ErrorMessage
:
1. What to do first?
Check and confirm that when running an org to org comparison in Gearset and including the same Flow
in the deployment package, the validation is actually successful and doesn't return the same error.
The source Salesforce org should be the org from which the Flow
is being originally migrated, while the target Salesforce org should be the one to which you're aiming to deploy this Flow
.
2. What to do if the org to org validation does not fail with the same error message?
The next step is to compare the content of the XML file of the Flow
found in your source Salesforce org versus the XML file of the same Flow
that is currently in your Git branch from which you aim to deploy the Flow
forward - e.g. to another Salesforce org, possibly via a CI job in Pipelines (such as from a Git environment branch to an org - if Pipeline workflow applies).
The reason why we ask you to compare the content of the Flow's XML between the two environments is because Salesforce may require the erroring component (in this example it's the ErrorMessage
) to be present in the source environment of your deployment.
For example, the required part of the Flow can be missing in the Git branch (source environment), and you'd need to include the missing bit in the Flow's XML in order for the validation to succeed.
In this context, it can be a Git to org CI job that is a part of your Pipelines workflow.
Note: If you're coming across the same validation error, but your use case is different, and the solution described in this support article doesn't work for you - please, contact us via in-app chat and we'll be happy to help!
How to resolve the error:
In the use case we've investigated, the org to org comparison did show that the part of the Flow
(highlighted in red on below screenshot) was not present in the source environment branch (Git to org CI job).
Adding that part to the XML of the Flow
to the Git branch (source of the deployment) resulted in a successful validation later on.
The issue seems to be that the XML includes the connector <customErrors>
, but the actual Flow
element definition <errorMessage>
is missing.
So the part that may be missing in your Flow
's XML may look like this:
<customErrors>
<name>API_NAME_OF_YOUR_CUSTOM_ERROR_COMPONENT</name>
<label>LABEL OF YOUR CUSTOM ERROR COMPONENT</label>
<locationX>NUMERICAL VALUE</locationX>
<locationY>NUMERICAL VALUE</locationY>
<customErrorMessages>
<errorMessage>ADD YOUR ERROR MESSAGE HERE</errorMessage>
<isFieldError>false</isFieldError>
</customErrorMessages>
</customErrors>
---
after the </decisions>
or </assignments>
tag.
Disclaimer: This error is returned by Salesforce directly, rather than Gearset. Even so, we offer guidance based on our combined experience with the Metadata API. Where possible, we try to help guide you to fix or avoid this error. In the case that this isn't possible, we may need to direct you to Salesforce support for further clarification.