All Collections
Feature guides
Comparisons and deployments
Running anonymous Apex code on your orgs
Running anonymous Apex code on your orgs
Run anonymous Apex code on your owned or shared org connections
Written by Emma Rawlings
Updated over a week ago

For those teams who have manual pre or post deployment steps, executing Anonymous Apex code can be an integral part of your release process.

Previously, you were able to run these apex scripts from within Salesforce but we now provide the option to run anonymous apex from within Gearset. This allows you to execute one-off scripts either pre-deployment (to prepare some state for the deployment that's about to be made) or post-deployment (to configure or modify something just deployed) depending on your needs.

Note: Execute Anonymous Apex is only supported on the Teams and Enterprise tiers.

This feature is only supported on Orgs that use OAuth connection methods i.e. 'Salesforce' or 'My Domain / Government Cloud' - the 'Username / password' method is not supported.

The apex script execution is done through the SOAP API so the user doing the execution will need both the Author Apex permission and the API Enabled permission.

You can run anonymous Apex from the Salesforce Org connection screen (see managing Salesforce org connections).

On a connection, expand the row and select the option to Run Anonymous Apex. This is possible from the My org connections table, or the Connections shared with me table. For shared connections, you must have been granted delegate-level access.

From here you will be prompted to enter your anonymous Apex code, with an optional description of the script that you've ran. Click Execute and the result will be shown including any errors in compiling or running the code.

Debugging Logs

As you can see from the screenshot above, you can also view the debug logs for an anonymous Apex execution. By default, the Apex_code logs are returned at DEBUG level, however you can select a specific log category and log category level from the dropdowns.

Additionally, if you do not want to view the logs, you can toggle them off with the View debug logs toggle or by setting the log category level to None.

Execution History

You can view the history of anonymous Apex executions from within Gearset against your connected orgs by switching to the History tab of the anonymous Apex execution modal.

This allows the user to view who is executing Apex against their org connection, when the code was executed, and what the result of the execution was.

Soon, the description of the script executed will also be available to view as part of this table.

Did this answer your question?