Salesforce CLI library for Ruby
This is a class library for introducing Salesforce CLI to Ruby scripting.
It is designed to be similar usability to the original command.
Currently only sf command is the target of development.
- official document
- rubygems
prerequisite
Salesforce CLI must be installed.
As of November in 2024, ver.2.64.8 is the development target.
install
- Rubygem
-
the simplest way:
$ gem install sf_cli
- Bundler
-
in Gemfile:
gem 'sf_cli'
then,
$ bundle install
Loading the module
require 'sf_cli'
Main features
Login to a org
sf.org.login_web
Get Object schema
sf.sobject.describe :Account
Get a record
sf.data.get_record :Account, record_id: 'xxxxxxx'
sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}
Execute SOQL
sf.data.query "SELECT Id, Name FROM Account LIMIT 1" # => [{Id: "abc", Name: "account name"}]
Create a record
sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}
Update a record
sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}
Delete a record
sf.data.delete_record :Hoge__c, record_id: 'xxxxxxx'
sf.data.delete_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}
Using Bulk API 2.0
sf.data.upsert_bulk sobject: :TestCustomObject__c, file: 'upsert.csv', wait: 5 # waiting for 5 minutes at maximum
Run Apex
sf.apex.run file: 'path/to/file'
sf.apex.run file: StringIO.new("System.debug('Hello World')")
Supported sf commands
- sf apex run
-
Run apex code
- sf apex generate class
-
Generate an Apex class
- sf apex generate trigger
-
Generate an Apex trigger
- sf data create record
-
Create a record
- sf data delete bulk
-
Delete records using Bulk API 2.0
- sf data delete record
-
Delete a record
- sf data delete resume
-
Resume a bulk delete job you previously started with Bulk API 2.0
- sf data get record
-
Get a record
- sf data query
-
Get records by SOQL
- sf data resume
-
View the status of a bulk job
- sf data search
-
Search objects using SOSL
- sf data update record
-
Update a record
- sf data upsert bulk
-
Update records using Bulk API 2.0
- sf data upsert resume
-
Resume a bulk upsert job you previously started with Bulk API 2.0
- sf lightning component
-
Generate a bundle for an Aura component or a Lightning web component.
- sf org display
-
Get a org’s connection information
- sf org list
-
List orgs you’ve created or authenticated to
- sf org list limits
-
List the limits in your org
- sf org list metadata
-
List the metadata components and properties of a specified type
- sf org list metadata-types
-
List the metadata types that are enabled for your org.
- sf org login web
-
Log in to a Salesforce org using the web server flow
- sf org login access-token
-
Authorize an org using an existing Salesforce access token
- sf project generate
-
Generate a Salesforce DX project
- sf project generate manifest
-
Create a project manifest that lists the metadata components you want to deploy or retrieve
- sf project retrieve start
-
Retrieve metadata from an org to your local project
- sf project deploy start
-
Deploy metadata to an org from your local project.
- sf sobject describe
-
Get a a Salesforce object schema
- sf sobject list
-
List all Salesforce objects of a specified category.