Click To Cloud DevOps Toolbox
This DevOps toolbox provides some of our daily used scripts, most of which
are Salesforce platform related, typically wrappers of some sfdx
commands.
For example, instead of
sfdx force:apex:execute -u myOrgAlias -f ~/test.apex
We simply do
dev execute ~/test.apex
No need to worry about the long usernames or alias. It automatically uses the name of the git repository as an alias.
For example, dev alias ^TAB
will list all user name or alias you have saved.
$ dev alias
[email protected] [email protected]
The toolbox runs on a Unix shell. The usual sh
or bash
is sufficient.
Many of the commands require sfdx
, which can be downloaded from the
Salesforce official site: https://developer.salesforce.com/tools/sfdxcli
The optional bash auto completion requires the package bash-completion
,
which can be downloaded from some package managers, for example brew
or
apt-get
.
brew install bash-completion
A recommended way of installation is cloning this repository, and including
the repository in your shell environment path. In this example, we are
using ~/.bashrc
as the shell startup script, though some shell may use other
startup script, e.g. ~/.profile
or ~/.bash_profile
.
git clone https://github.com/Click-to-Cloud/DevOps.git
echo "PATH+=:$PWD/DevOps" >> ~/.bashrc
Then restarting your bash, or running source ~/.bashrc
, will get things
ready.
To include the bash completion feature, append this code to your bashrc.
echo "source $PWD/DevOps/bash_completion.d/dev" >> ~/.bashrc
Suppose you are working on a git repository, run dev login
if you haven't
done so. After connecting to a Salesforce org, everything command you use
inside the git repository will be against the org you just logged in.
When you want to switch to another org for the same repository, you can do
another dev login
. Alternatively, if a username has been used to log in
previously, you can run dev alias [email protected]
. You can check
all available usernames by auto completing the third argument of
dev alias ^TAB
.
Do OAuth login and associate the login information with the current repository.
An optional third argument url
is available, which can be only either
'test.salesforce.com' or 'login.salesforce.com'. If this argument is ommitted,
the login will go to 'test.salesforce.com' by default.
The third argument can be auto completed.
dev login login.salesforce.com
dev login
Open the org in the default browser without using password. If the alias
or
username
is provided, it would open the org according to the provided login
information, otherwise, it would choose the alias on the repository to open.
The alias
or the username
must have been used in the dev login
at least
once. More specifically, after running dev login
on the repository
'Query' using the username '[email protected]', the OAuth information of
'[email protected]' will be saved, and 'Query' will be linked to the username
'[email protected]'. In this case we can use dev open Query
or
dev open [email protected]
to open the org on the browser. Alternatively, if
we have already navigated ourselves inside the 'Query' repository , we can
omit the third argument, running dev open
only.
If the username
is not provided, the command will list all alias with its
associated username.
If a username
is given, the command will replace the associated username
of the project with the given username
.
The third argument can be auto completed.
Compile the class/page/trigger files and deploy it to the associated org.
A file can be any of these types: Apex Class, Apex Page, Apex Trigger.
dev compile Query.cls TriggerOnAccount.trigger HomePage.page
By default, it will look for the files using the relative pathname. If not
found it will look for the files in the src/classes
, src/pages
or the
src/triggers
directories.
It is required that the related meta XML files are located in the same directory.
For example, calling dev compile Query.cls
, the script will try to find
Query.cls
in the current directory. If not found, it will look for Query.cls
in the directory src/classes
. If, for example, finding the Query.cls
in the
current path, the script will use the Query.cls-meta.xml
file in the same
directory for the deployment. If the Query.cls-meta.xml
file is missing, the
deployment will fail.
The arguments can be auto completed.
Execute unit tests. If test_classes
is provided, it will execute all test
code within those classes. Otherwise, it will execute all test code in all
classes.
The arguments can be auto completed.
Execute an SOQL query and print the result to standard output.
To avoid some of the characters, e.g. single quote, less than sign, being
parsed as bash operators, it is recommended that the soql_expression
is surrounded by double quotes.
dev query select id from account
dev query "select id from account where name = 'Jack' and createddate >= today"
Some keywords in SOQL can be auto completed, e.g. select, from, etc.
Execute anonymous apex code from the standard input.
If the command is dev execute
, it reads the user terminal input as the
standard input. In this case, we can type multiple lines of apex codes,
then type CTRL-D indicating the end of file to finish.
Alternatively, we can write the apex code in a file, then pass the file name as an argument.
dev execute test.apex
Print detail of a record to standard output.
Print the fields of an object to standard output.
Print the full schema information of an object to standard output.
Print the return value of an apex expression to standard output.
dev debug "UserInfo.getUserId()"
If directory
is not provided, it will use ./src
as the directory.
Deploy the all the files in the directory to the Org. It is required that the
package.xml
file is located in the directory.
If directory
is not provided, it will use ./src
as the directory.
Retrive all the files from the Org using the package.xml
in the directory.