Error overview
You may run into this Salesforce validation error when pushing either new or changed Apex class components.
An example of the error message in our app would be:
"Variable does not exist: Primary__c"
Explanation of the error
In the above example Primary__c is a Custom field referenced in the XML of failing Apex class component (CaseTriggerHandlerExtension).
The reason why the error happens is because Primary__c field is required in the target Salesforce org before the Apex class referencing it can be deployed.
Resolution
Whether you're making your deployment via Compare and deploy, or if your pull request is failing validation in the Gearset Pipeline, the resolution to this error will likely require you to break the deployment down in two steps.
Workaround in Compare and deploy
Make sure you prioritise the deployment of the missing variable(s) referenced in the error message.
deploy the(se) variable(s) as part of separate deployment. Use Compare and deploy.
Once done, you can proceed with the deployment of the failing Apex class(es).
Workaround in Gearset Pipelines
On your Deployment pipelines page consider committing the missing variable(s) into a new feature branch.
Push the variables them through the Pipeline, make sure they get deployed to the environment against which your PR with Apex classes is failing.
Once the PR with variable(s) is deployed successfully, re-validate the original PR that contains the failing Apex classes. This should hopefully help your PR pass the validation, and allow you to merge the PR. CI job will do the rest and deploy the Apex classes to the target org.
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.


