Visual Studio Code Tips – Execute SOQL in Visual Studio Code

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 workbench.developerforce.com – […]

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 workbench.developerforce.com
– 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 – https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/reference_objects_list.htm

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 – https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/reference_objects_list.htm

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]);
system.debug(‘Accounts::’+accounts);
system.debug(‘Contacts::’+contacts);
system.debug(‘Cases::’+cases);
system.debug(‘Opportunities::’+opportunities);
system.debug(‘Leads::’+leads);

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

Reference:-

SOQL and SOSL Queries  – https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL.htm
Introducing Tooling API – https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/intro_api_tooling.htm
Write SOQL Queries from Trailhead Module – https://trailhead.salesforce.com/en/content/learn/modules/apex_database/apex_database_soql

The post Visual Studio Code Tips – Execute SOQL in Visual Studio Code appeared first on TheBlogReaders.com.

ASNF

Next Post

I reckon these could be some of the best investments in 2020

Sat Aug 15 , 2020
If you’re looking for the best investments to make in 2020, your timing could be good. For example, last week’s figures from the Office for National Statistics showed a dire plunge in GDP for the second quarter of the year. But there were encouraging signs of recovery in May and […]