How to Utilize Salesforce CLI sf (v2)

on

|

views

and

comments

Table of Contents

Introduction

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem, it’s a daily companion for Salesforce Developers. Its role in DevOps practices, such as continuous integration, is fundamental. Now, after seven years of general availability, we’re stepping into a new era for the Salesforce CLI.

Embrace the future

This is the way forward for Salesforce Developers. You will thank Salesforce for making this command more powerful and faster. The installation and update times are also significantly less. It is more capable and simpler to remember. Furthermore, there will be new plugins and features for the new version of Salesforce CLI sf(v2)

What's changed

First of all, the prefix of the command has been changed from `sfdx` to `sf`. The flags are also more intuitive and easier to remember. For example to create a scratch org earlier, you used to make commands like the below:

ravigrover@Ravis-MacBook-Pro ApexDebuggerProject % sfdx force:org:create -f config/project-scratch-def.json -a MyScratchOrg
Warning: The force:org:create command is deprecated. Try “org create scratch” or “org create sandbox” instead.
Warning: Record types defined in the scratch org definition file will stop being capitalized by default in a future release.
Set the `org-capitalize-record-types` config var to `true` to enforce capitalization.
Successfully created scratch org: 00DHE000000Q32H2AS, username: test-zc1afdvpvqmz@example.com.
ravigrover@Ravis-MacBook-Pro ApexDebuggerProject %

Now, with sf-style commands coming into the picture, see how easy it is to remember the clauses and no need to use a colon after each word in the command like below:

ravigrover@Ravis-MacBook-Pro ApexDebuggerProject % sf org create scratch –target-dev-hub apxdbgrdevhub –definition-file config/project-scratch-def.json –set-default –duration-days 3

Warning: Record types defined in the scratch org definition file will stop being capitalized by default in a future release.
Set the `org-capitalize-record-types` config var to `true` to enforce capitalization.
Creating Scratch Org…
RequestId: 2SRdL0000000TEvWAM (https://capgeminiaustralia27-dev-ed.develop.my.salesforce.com/2SRdL0000000TEvWAM)
OrgId: 00DC10000013PhF
Username: test-ayuqfpdf4b8x@example.com
✓ Prepare Request
✓ Send Request
✓ Wait For Org
✓ Available
✓ Authenticate
✓ Deploy Settings
Done

Your scratch org is ready.

Also, it is noteworthy here that new features and fixes will be going only to sf instead of sfdx, but having said that, you can still use old sfdx-style commands. Look at this example to see how commands have become more intuitive and easier to remember below:

ravigrover@Ravis-MacBook-Pro ApexDebuggerProject % sfdx force:source:push
Warning: We plan to deprecate this command in the future. Try using the “project deploy start” command instead.
Pushing v59.0 metadata to test-ayuqfpdf4b8x@example.com using the v60.0 SOAP API.
DEPLOY PROGRESS | ████████████████████████████████████████ | 14/14 Components
Updating source tracking… done

=== Pushed Source

STATE   FULL NAME            TYPE                     PROJECT PATH                                                                    
─────── ──────────────────── ──────────────────────── ────────────────────────────────────────────────────────────────────────────────
Created AccountService       ApexClass                force-app/main/default/classes/AccountService.cls                               
Created AccountService       ApexClass                force-app/main/default/classes/AccountService.cls-meta.xml                      
Created AccountServiceTest   ApexClass                force-app/main/default/classes/AccountServiceTest.cls                           
Created AccountServiceTest   ApexClass                force-app/main/default/classes/AccountServiceTest.cls-meta.xml

With sf executable, same command will look like below:

 

ravigrover@Ravis-MacBook-Pro ApexDebuggerProject % sf project deploy start
Deploying v59.0 metadata to test-ayuqfpdf4b8x@example.com using the v60.0 SOAP API.
Deploy ID: 0AfC1000004L5gjKAC
Status: Succeeded | ████████████████████████████████████████ | 1/1 Components | Tracking: 4/4

Deployed Source
==========================================================================================================
| State   Name       Type                     Path                                                        
| ─────── ────────── ──────────────────────── ────────────────────────────────────────────────────────────
| Created demoLWCOne LightningComponentBundle force-app/main/default/lwc/demoLWCOne/demoLWCOne.html       
| Created demoLWCOne LightningComponentBundle force-app/main/default/lwc/demoLWCOne/demoLWCOne.js         
| Created demoLWCOne LightningComponentBundle force-app/main/default/lwc/demoLWCOne/demoLWCOne.js-meta.xml 

Get started with Salesforce CLI sf (v2)

To try the new command style, you have to uninstall sfdx. The instructions are here.

To determine the equivalent commands from sfdx style to sf style, please refer to this resource. Besides simply switching the name of the executable from sfdx to sf, there are a number of changes that apply to CLI commands when upgrading your projects. The Salesforce CLI documentation provides a good overview of these changes.

Legacy sfdx style command

Equivalent sf-style command

Comments

sfdx force:org:delete -p -u recipes

sf org delete scratch -p -o recipes

The scratch subcommand needs to be added.

The target org flag changes from -u to -o.

sfdx force:org:create -s -f config/project-scratch-def.json -d 30 -a recipes

sf org create scratch -d -f config/project-scratch-def.json -y 30 -a recipes

The scratch subcommand needs to be added.

The “assign default org” flag changes from -s to -d.

The scratch org duration flag changes from -d to -y.

sfdx force:source:push

sf project deploy start

This is a significant change, but the new command works for all project formats (source or metadata).

Previously, you needed distinct commands.

sfdx force:user:permset:assign -n recipes

sf org assign permset -n recipes

The topic changes from user to org and the order of the sub commands changes.

sfdx force:data:tree:import -p data/data-plan.json

sf data import tree -p data/data-plan.json

Imports the data from plan.json

sfdx force:org:open -p lightning/n/Hello

sf org open -p lightning/n/Hello

Opens the component in the org

sfdx force:apex:test:run -c -r human -w 20

sf apex test run -c -r human -w 20

Sets the execution of test classes

Closing words

To conclude this short overview of the migration from sfdx-style commands to sf-style commands, you will be more likely to remember the wordings of every command since sf-style commands are more like human language and easier to write.

Resources

Salesforce CLI GitHub repository for checking out the source code or the release notes, leaving feedback and, reporting issues

Must Read

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Salesforce Short Codes

Hello Awesome Developers/Admins, On this page, I am going to update all the small reusable utilities which will be useful for any developer or admin. Link...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential