Skip to main content
How to deploy Precision deployment of Apex code

Gearset can help you deploy individual line changes to Apex code and triggers

Quinn Kuiper avatar
Written by Quinn Kuiper
Updated over a week ago

Gearset can help you break down Apex into individual lines and deploy them to the target. Using the precision deployment of Apex code you are now able to deploy individual line changes to Apex.

How to use precision deployment

To be able to use precision deployments of Apex, you need to ensure that the Apex class is a changed object in the comparison.

Choose the Apex class from the comparison grid. The green changes on the left indicate inclusions; select these to add them to the package. The red changes on the right indicate deletions; select these to remove them from the package.

Now you can use the preview changes tab to double-check that the Apex is how you're expecting it, and you can double-check for any common mistakes.

Preview selections and check syntax

The preview selections tab in the comparison allows users to easily see what the final Apex code will look like, before deploying selected changes.

Gearset will also perform a syntax check to help identify potential issues with the selections leading to more successful deployments:

Other considerations

Selecting all differences

To select all Apex differences either:

  • Select the Apex class in the comparison table, or

  • Click "Selected" checkboxes for both the source and the target in the diff view window

Modifying lines

Unlike in precision deployments of XML, Gearset does not link changes together, so you need to take care when deploying changes, if there is a new line in the source that replaces one in the target, make sure to select both sides, being sure to check. This ensures that duplication of Apex does not occur.

In our experience we have also seen differences in formatting between source and target. If it is a git to org comparison (or vice versa) ensure that the changes are selected on both source and target, so this duplication does not occur.

Since Apex code is only validated during deployment to Salesforce orgs, when deploying to a Git branch, you have the ability to commit faulty Apex code. This can lead to validation errors when you eventually deploy it to an org.

Example

In this example, we have changed an integer value, and forgotten to select the deletion as well as the inclusion.

Here if we check the preview selections, notice that the value has been duplicated.

Trailing comma

If a line you're excluding from your selection has no trailing comma, the Apex will not validate as expected.

Example

In this example Dev A has added Belgium to the list but their teammate (Dev B) has added Portugal before Dev A could deploy. Unfortunately Dev A now can’t deploy only Belgium because it would leave a trailing comma, which is considered invalid Apex.

To fix this Dev A, reorders the changes so that their change is the last on the list and can therefore deploy only their addition.

Did this answer your question?