REPL is an acronym for a read-eval-print loop.
From Wikipedia
A simple, interactive computer programming environment that takes single user inputs, evaluates them, and returns the result to the user.
This is a simple program that executes commands against Salesforce and returns the result as JSON.
- Configuration profiles to easily connect to different Salesforce accounts
- Query REST API usage information
- Retrieve Salesforce sobject lists, descriptions, and specific object details
- Execute SOQL queries
- Persistent command history (use ⬆️ ⬇️ to cycle through the history)
- Pipe command output to other programs (like the amazing ./jq utility for processing JSON)
- Composer
- PHP 7.0 >
- Access to a Salesforce account
- Salesforce account username
- Salesforce account password
- Salesforce account security token
- Salesforce OAuth consumer key and secret. This requires a Salesforce connected app
- Clone this repository
- Inside the project directory, run
composer install
- Create the file
config.ini
usingsample.config.ini
as a guide
- Run
php artisan repl <profile-name>
- Type
?
orhelp
in the REPL to see a list of available commands - Type
exit
or pressCTRL-D
to exit
Command | Description |
---|---|
o all |
See a list of all available sobjects |
o describe <sobject> |
Describe a single sobject |
o <sobject> <salesforce id> |
Show the details of a specific Salesforce object. |
q <soql> |
Execute an SOQL query |
u |
Display REST API usage information |
Running a command like o all
will return all of the data about all sobjects. With piping and the great ./jq utility, you can easily filter those results down.
For example, o all | jq '.sobjects | .[] | {label: .label}'
will display only the label of those sobject.
You could also filter the u
command to only display daily api request limits with a command like u DailyApiRequests | jq '[{Max: .Max, Remaining: .Remaining}]'
You can specify a single command with the --exec
argument.
For example: `php artisan repl fcgs --exec="u DailyApiRequests | jq '[{Max: .Max, Remaining: .Remaining}]'"
New commands can be added by creating a command class that extends AbstractCommand
in the app/Commands directory.
Commands must have $helpText
and $titleText
properties containing any help text to display and the name of the command. These will be displayed when a user executes the help command.
Commands must have an aliases
method which returns an array of aliases that can be used to run the command
Commands must have a run($fields, $parent)
method which will be called when the command is executed.
run
method parameters
$fields
An array of everything typed after the command name. Pipes (|
) are not included in $fields
as they are executed automatically after the command runs.
$parent
An instance of the repl Console\Command
class. This is useful if your command needs to prompt for input or display output
This script requires a custom Salesforce Connected App in order to access the Salesforce REST API.
- Click on your profile name in Salesforce and click Setup
- Under App Setup, click Create and Apps, then click the New button under Connected Apps
- Give the app a unique name and label.
- Make sure that Permitted Users is set to All users may self-authorize
- Make sure that IP Relaxation is set to Relax IP restrictions
- Make sure that Refresh Token Policy is set to Refresh token is valid until revoked
- Make sure that Selected OAuth Scopes is set to Full access
- You can put anything for Callback URL since the script won't actually be redirecting to it.
To edit existing connected apps
- Click on your profile name in Salesforce and click Setup
- In the Quick Find box, type connected apps
- In the results list on the left, click on Connected Apps
- Click Edit next to the name of the connect app you wish to edit