Visual Studio Code Tips – Execute SOQL Query in Visual Studio Code

This post & video explained about to Execute SOQL in Visual Studio Code:

– Execute SOQL Using Rest API and Tooling API
– Execute SOQL in Developer Console
– Execute SOSL in Developer Console
– Execute SOQL in
– Execute SOQL in Data Loader
– Execute SOQL in Visual Studio Code
– Execute SOSL Using Anonymous Apex in Visual Studio Code

From Scripts -> SOQL -> Create a file with extension as .soql

From Command Palette (Ctrl+Shift+P) -> Type Execute SOQL and Select “SFDX: Execute SOQL Query with Currently Selected Text“, results appear in the Output panel as highlighted below screenshots

SFDX Command for Query Execution using Rest API

sfdx force:data:soql:query –query Select Id, Name, Type From Account

Defaults the Query Executed using the Rest API and some of the query supported only with Tooling API then select the Tooling API as highlighted.

Refer Salesforce Article about Tooling API Supported Objects list –

SFDX Command for Query Execution using Tooling API

sfdx force:data:soql:query –query Select Id, FullName from ApexClassMember –usetoolingapi
SFDX Command for Query Execution with JSON Results
sfdx force:data:soql:query -q “SELECT Id, Name, Type FROM Account” –json

Execute SOQL using Tooling API in Visual Studio Code

Execute SOQL using Tooling API in Developer Console:

From Query Editor -> Check the Use Tooling API 

Tooling API Support Object List –

Execute SOSL using Developer Console:

Execute SOSL using Visual Studio Code Anonymous Apex:

From Scripts -> Apex -> demo.apex folder, Execute SFDX:Execute Anonymous Apex with Currently Selected Text

List<List<SObject>> searchList = [FIND ‘Sakthi*’ IN ALL FIELDS RETURNING
                            Account (Id, Name),
                            Contact (Id, FirstName, LastName),
                            Case (Id, CaseNumber, Subject),
                            Opportunity, Lead];
Account [] accounts = ((List<Account>) searchList[0]);
Contact [] contacts = ((List<Contact>) searchList[1]);
Case [] cases = ((List<Case>) searchList[2]);
Opportunity [] opportunities = ((List<Opportunity>) searchList[3]);
Lead [] leads = ((List<Lead>) searchList[4]);

Please check the below video for more info about to Execute SOQL in Visual Studio Code:


SOQL and SOSL Queries  –
Introducing Tooling API –
Write SOQL Queries from Trailhead Module –

Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

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