Salesforce SOQL & Apex Runner
A VSCode extension that provides a comprehensive interface for executing SOQL queries and Anonymous Apex code against Salesforce orgs, similar to Illuminated Cloud's functionality in IntelliJ.
Features
- SOQL Query Execution: Execute SOQL queries and view results in a formatted table
- Anonymous Apex Execution: Run Anonymous Apex code and view debug logs
- Multi-Org Support: Configure and switch between multiple Salesforce orgs
- Bottom Panel Interface: Integrated panel similar to VSCode's terminal
- Real-time Results: View query results and debug logs in real-time
Installation
Install the dependencies:
npm install
Compile the TypeScript code:
npm run compile
Press F5
to launch the extension in a new Extension Development Host window
Usage
Opening the Extension
- Use the command palette (
Ctrl+Shift+P
/ Cmd+Shift+P
) and search for "Open Salesforce SOQL & Apex Runner"
- Or use the keyboard shortcut
Ctrl+Shift+S
/ Cmd+Shift+S
Adding a Salesforce Org
- Click "Add Org" in the extension panel
- Fill in the required fields:
- Org Name: A friendly name for your org
- Instance URL: Your Salesforce instance URL (e.g.,
https://mycompany.my.salesforce.com
)
- Access Token: Your Salesforce access token
- API Version: Salesforce API version (default: 58.0)
Getting an Access Token
To get an access token for your Salesforce org:
Using Browser/Connected App:
- Set up a Connected App in your Salesforce org
- Use OAuth flow to get an access token
Using SFDX CLI (if you have it installed):
sfdx force:org:display --verbose -u your-org-alias
Using VS Code Salesforce Extension:
- If you have the official Salesforce Extension Pack installed
- Check the
.sfdx
folder in your project for org information
Running SOQL Queries
- Select "SOQL" mode
- Choose your target org from the dropdown
- Enter your SOQL query in the text area
- Click "Run"
Example SOQL query:
SELECT Id, Name, Email, CreatedDate
FROM Contact
WHERE CreatedDate = TODAY
LIMIT 10
Running Anonymous Apex
- Select "Anonymous Apex" mode
- Choose your target org from the dropdown
- Enter your Apex code in the text area
- Click "Run"
Example Anonymous Apex:
System.debug('Hello World!');
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 5];
for (Account acc : accounts) {
System.debug('Account: ' + acc.Name);
}
// Create a new contact
Contact newContact = new Contact(
LastName = 'Test',
Email = 'test@example.com'
);
insert newContact;
System.debug('Created contact with ID: ' + newContact.Id);
Configuration
The extension stores org configurations in VSCode settings. You can also manually edit them:
- Open VSCode settings (
Ctrl+,
/ Cmd+,
)
- Search for "salesforce-runner"
- Edit the "Orgs" configuration
Security Notes
- Access tokens are stored in VSCode settings
- Be careful not to commit access tokens to version control
- Consider using environment variables or secure storage for production use
- Access tokens can be rotated/revoked from your Salesforce org
Troubleshooting
Common Issues
- "Org not found" error: Make sure you've selected an org from the dropdown
- Authentication errors: Verify your access token is valid and hasn't expired
- SOQL errors: Check your SOQL syntax and object/field permissions
- Apex compilation errors: Review the debug logs for compilation issues
The extension provides detailed error messages in the results panel. For additional debugging:
- Open VSCode Developer Tools (
Help > Toggle Developer Tools
)
- Check the Console tab for extension logs
- Look for network errors or API response details
Development
Building from Source
- Clone the repository
- Install dependencies:
npm install
- Compile:
npm run compile
- Run: Press
F5
in VSCode
Project Structure
├── src/
│ ├── extension.ts # Main extension entry point
│ └── salesforce-api.ts # Salesforce API integration
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
└── README.md # This file
License
MIT License - feel free to use and modify as needed.
Contributing
Feel free to submit issues and pull requests to improve the extension!