License requirements:
Execute Anonymous Apex is only supported on the Deployment Teams and Enterprise tiers.
For those teams that 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: 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.
Running anonymous apex with one of your Salesforce connections
You can run anonymous Apex from the Salesforce orgs page in Gearset (see managing Salesforce org connections).
On an org connection, expand the row and select the option to Run Anonymous Apex
.
This is possible from both My org connections
or Team-shared org connections
tabs.
In a Connections shared with me
tab you'd need to click on the icon here to run anonymous apex.
โ
Access level required to be able to run anonymous apex on a shared org connection:
โThe owner of the org connection shared with you must first grant you a Deployment
level access to the org. This can be done via delegate-level access feature
From here you will be prompted to enter your anonymous Apex code, with an optional description of the script that you've run.
You can Validate
the code, this will check that the script will compile correctly but will not execute it.
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 drop-down under Configure Execution
tab.
If you do not want to view any logs, you can untick Include debug logs
checkbox, or you can set the category level to None
(as on below example).
Configure Execution
In this tab you can select what you would like to execute when running the Apex tests. This allows you to configure the debug logs that are requested for an execution, therefore you can request the relevant logs accordingly.
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.
Running anonymous apex associated with one of your deployments
After one of your deployments completes successfully, the deployment success screen allows you to run anonymous apex against the target of the deployment. The button for this can be found in the bottom right of the page.
This will open the anonymous apex modal. Any apex executions which you perform from here will be associated with this deployment. History items on the anonymous apex modal for that org connection will link to this deployment.
When you are on Salesforce orgs page in Gearset, and select Run Anonymous Apex
for the target org on which the anonymous apex was run, and navigate to History
tab, you'll see an option to View Deployment summary
.
โ
Looking to preview anonymous apex for one of the past deployments?
After the deployment was made, when you click on View details
on your Deployment history for a deployment where anonymous apex was executed, there should also be an indication of the last execution's result status.
If you select Anonymous Apex
tab, you will see a full listing of all anonymous apex executions which are associated with your deployment.