function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gabriel Martins 13Gabriel Martins 13 

Unable to run SOQL on Visual Studio

Hello everyone, I'm facing an issue with the Visual Studio when trying to run any SOQL statment.

Step to reproduce:

1. Create a new file
2. Paste the SOQL statment: SELECT Name FROM Contact
3. Save the file with the extension .soql
4. Highlight  the SOQL statment in the file
5. On comand Pallet Execute SFDX: Execute Anonymous Apex with Currently Selected TEXT

It does not work. I get the golowing error message: Unexpected token 'SELECT'.

Any idea?

thanksUser-added image

Best Answer chosen by Gabriel Martins 13
ANUTEJANUTEJ (Salesforce Developers) 
Sorry Gabriel,

When I tried SFDX: Execute Anonymous Apex with Currently Selected TEXT I was getting the above error but when I used this 
SFDX: Execute SOQL Query with Currently Selected Text command I was able to retrieve the records can you try the soql with this command and see if it works.

>> You can also check this article: http://theblogreaders.com/visual-studio-code-tips-execute-soql-visual-studio-code/

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Gabriel,

I also tried the same in my dev org and I see the same error let me check internally and respond.

Thanks,
Salesforce Support
ANUTEJANUTEJ (Salesforce Developers) 
Sorry Gabriel,

When I tried SFDX: Execute Anonymous Apex with Currently Selected TEXT I was getting the above error but when I used this 
SFDX: Execute SOQL Query with Currently Selected Text command I was able to retrieve the records can you try the soql with this command and see if it works.

>> You can also check this article: http://theblogreaders.com/visual-studio-code-tips-execute-soql-visual-studio-code/

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
This was selected as the best answer
Gabriel Martins 13Gabriel Martins 13
Thank you very much ANUTEJ! Helped a lot!