Learning something new every day is essential for growth in a career. A few weeks ago, I learned something new that I am sharing with you. We usually run the query via Developer Console. It doesn’t allow us to save the queries, so you have to write the query or copy-paste from somewhere every time.
No worries anymore! The solution is right here for you!
Visual Studio Code does that fantastic job here. Kudos to the Salesforce SFDX team for launching query capabilities to it.
Before processing ahead, if you haven’t gotten a chance to read my last blog on Inline Editing in Reports, please do so now. It will help you to update a field in the record without moving to the record pages.
Let’s start with a real-time use case.
Sara William is working as a Consultant at Appiuss Softwares. She wanted to execute as well save the query for future reference.
Sara wants to find out the account records which have open opportunities with amounts greater than half a million.
Connect Visual Studio Code to the org in which you want to execute the query.
Use this link to set up and connect your org with Visual Studio Code.
- Click on the Explorer icon.
- Go to Project name | Scripts.
- Right-click on soql | New File ( give the file name i.e. Account.soql ).
- Click on the file name and type or copy-paste the query.
- Select the query you want to execute, written in step 4.
- Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
- Make sure the new prompt starts with >
- Search for SFDX:Execute SOQL Query with Currently Selected Text and press Enter.
- Click on REST API Execute the query with REST API.
The output will look like below, and the query saved in the file. You can reuse this query again whenever is required. Multiple queries can be saved in one file if needed.
You are Done!!!
I would love to hear about your experience with Visual Studio Code to execute SOQL, Apex code. How do you use it?