Developer Console Execute Anonymous

By in , , ,
2333
Developer Console Execute Anonymous

Developer Console Execute Anonymous

In a previous blog post, we discussed at a high level how Developer Console can be used to view and query data within your Salesforce instances.  In this article, we are going to walk through how to use the Open Execute Anonymous window to perform actions on your data en masse.  Keep in mind that if you want to only take action on a single row of data, the Query Editor allows you to in-line edit records that are returned from your query.

 

To begin, navigate to Developer Console in your Salesforce instance and click the Debug Menu.  From there you will click the Open Execute Anonymous option.

Once you click on the Open Execute Anonymous Window option, a pop-up window will appear in your browser which looks like this.

 

Once you are at this point, you are able to do a variety of actions.  One thing I will showcase today is how you can quickly delete records (the same logic would apply to updating data as well, however that would require a more complex script).  For this scenario, I am going to delete all Accounts in the system where the Active field on the Account is set to “No”.  I first would want to query the dataset to make sure my query returns accurate results.  Here are the returned values for my query of SELECT Id, Active__c from Account WHERE Active__c = ‘No’.

 

You can add more columns if needed, to get more details about the rows that meet the query criteria.

However, in this scenario, I know that those 4 Accounts are the ones I want to delete.

 

Then, Execute the Anonymous window and input the same query while adding a delete before the query.  I will also need to encapsulate the query in brackets.  That delete command will look like this:

Delete[SELECT Id, Active__c from Account WHERE Active__c = ‘No’];

I can then paste this command directly into the Execute Anonymous window.

Hit the Execute button which will start the process of deleting the 4 records which meet the criteria.  Depending on the size of the job it can take a few seconds for it to complete. In this case, we have seen an instant completion.

If you want to confirm whether the rows are deleted or not, Query the same dataset.

This is how you can leverage the Developer Console to complete more complex tasks in your environment.

Stay connected to know more about the Developer Console that we often leverage to help our clients be successful.

 

Additional Resource

Workbench Export Types

Dynamic vs. Static Queries

Leave a reply

Your email address will not be published. Required fields are marked *