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.

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.

Prerequisite

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.

Solution

  1. Click on the Explorer icon.
  2. Go to Project name | Scripts.
  3. Right-click on soql | New File ( give the file name i.e. Account.soql ).
  4. Click on the file name and type or copy-paste the query.
  1. Select the query you want to execute, written in step 4.
  2. Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
  3. Make sure the new prompt starts with >
  4. Search for SFDX:Execute SOQL Query with Currently Selected Text and press Enter.
  1. 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?

Join our newsletter.

No spam, just learning!

Continue Reading

Get a free consultation.

Call us today at (469) 790-0063

Schedule a Consultation

Leave a Reply