First Contribution to the SFDX CLI

I’ve been pushing some of the non-technical folk within Caddify to adopt the Salesforce CLI for some time. I find the ability to manage logins to different orgs a huge win and know that others benefit from this greatly also. And it was during one of these conversations with our CEO that he said “now if it could open orgs in different browsers that would be amazing”… and that got me thinking.

See the plugin’s changes in action in this video.

I have created several SFDX CLI plugins that we use internally (mostly managing scratch org creation and setup) and am very familiar with node and TypeScript so saw this as a great opportunity to see if I could implement a change that meant the DX org:open commands could target specific browsers on the user’s computer.

I had read – fairly recently – about the new modularisation of the SFDX CLI project, and was excited by this as I remember hearing from the Salesforce folk years ago when SFDX was initially released, and I asked about whether or not they’d planned to open source it all, and was told that it would be indeed be one of the end goals. Anyway, off I went to find the repository that supported the org namespace. After forking the project and pulling it down to my local development environment I was able to see that made use of the open node package, so in turn I made my way to their npm page to see if anything existed already to support “browser targeting”… and there it was, the project supported optional parameters to achieve just what I was after.

Within less than half an hour I had a working proof of concept on my local machine. I then turned to the Contributing section on the DX repo to see how I could get involved, and from there I created a new issue against the repo, mentioning that I’d love to create a PR to implement the new functionality. Only a short while later I had a response from the team, welcoming my input.

I proceeded to more properly implement the change (you know, with tests and that) and submitted my PR. I was honestly bowled-over by the welcoming, supportive, and helpful responses to my PR from the whole team. I was given guidance on naming, implementation, help messages, and all sorts… and I guarantee that the end code that was merged into the plugin’s repo was many times better than my first iteration. Huge thanks to Shane McLaughlin and the whole team for their support and patience.

This new feature is available in the v1.9.0 release of the plugin-org plugin.

In short, the new functionality is really useful, and I’d love to hear your thoughts on it, and also, if you think that the DX CLI could do with new features or improvements then dive on in and get involved.

Lightning Web Components Specialist – Trouble getting the boatMap Component?

During the completion (as if writing I’m on step 8) of the new ​Lightning Web Components Specialist Trailhead superbadge I had some troubles with step 6 as I couldn’t get access to the source of the boatMap component.

It’s installed from an unlocked package, and being a LWC it’s not viewable in the Salesforce developer console. I was also unable to see it in the Org Browser VS Code plugin… but then I went back to my old friend the CLI.

Using this command I was able to bring the source down into my repo.

sfdx force:source:retrieve -m LightningComponentBundle:boatMap

 

I hope this saves folk some time as they work through this badge.

SFignore: The .forceignore Salesforce SFDX Plugin

Salesforce SFDX projects are a great way to build both declaratively and through code for the Salesforce platform. It’s very common to want to ignore particular files from being pushed or pulled between Orgs and your local project, and this is achieved through .forceignore file. The file has some odd (and undocumented) syntax however, and the process is also known to have a few bugs, and getting the right entries in the file can be hard… and that’s where the SFignore SFDX plugin comes in.

The .forceignore file and the process behind it is sprinkled with black magic – Todd Halfpenny, 2020

I’ve created the SFignore plugin initially through an internal need for the work I’ve been doing with the Caddify project at MobileCaddy. A lot of this work has been around using Salesforce 2GP (second generation packaging) tools to create packages for our new product. Our workflow includes pushing, pulling, deploying to many different shape orgs and includes a fair bit of code and metadata that is used solely for non-production scenarios (test setup, demo data, org cleaning, etc) and we want to make sure that nothing accidentally gets put into our managed package releases. The .forceignore file that is used by the SFDX CLI tooling and tracking allows us to do this – or most of it at least… but it’s syntax is nuanced and is lacking in documentation.

The SFignore plugin gives me an easier way to add entries to the .forceignore file, by taking away the guessing of syntax and the need to remember the correct suffixes for the different metadata types. This is useful, as would you know (or remember) if the correct suffix for a SiteDotCom entry should be SiteDotCom, siteDotCom, or site? And what about AppMenu? Would you know whether to use appMenu, AppMenu, Menu, menu? Only one of these is right, and the syntax differs further depending on whether the change is local or remote. Oh you also need to encode (some) special characters too… if you didn’t know that then this could be why your entry for “Custom: Sales Profile.profile” isn’t working as you expected.

The initial release only supports entries for remote changes, and only a subset of metadata types that I’ve had to use so far… but the roadmap for it includes;

  • Support for local syntax
  • Wildcarding – currently only supports specific entries
  • An extension for vscode.

Here’s an example of using the plugin, where we’re wanting to add an entry to ignore pulls for the profile Custom: Sales Profile.

sfdx sfignore:add -n "Custom: Sales Profile" -m Profile

This results in the following entry being added;

Custom%3A Sales Profile.profile

The -m flag specifies the metadata type, and the valid values should match those as seen on Salesforce’s metadata coverage report and the output of a sfdx force:source:status command.

It should also be noted that something’s appear to be impossible to achieve with the .forceignore file, including;

  • Adding some tests – yeah, sorry
  • Specifying specific custom fields
  • Specifying specific custom metadata
  • Specifying specific record types

If you know how to achieve the above I’d be very happy to hear about it.

You can find the source for SFignore SFDX plugin on github, and you can download it from the npm registry too

sfdx plugins:install sfignore

If you use the plugin and need more metadata types added then please raise an issue on github, or even better fork the repo and create a PR.

sf-package-version-checker – SFDX Plugin to notify on completion of Salesforce Package Builds

If you’ve ever built Salesforce packages with the SFDX commands (in fact long before this) you’ll know that the creation of a package can take some time, especially if your package has dependencies.

At MobileCaddy we’ve been adopting the SFDX CLI as much as we can – and in fact embracing the SFDX ethos as a whole – and recently we’ve been working with the Salesforce second-generation packaging (2GP). During this I’ve found that the standard SFDX command to create a package version would continue to give me status updates every 30 seconds for 10 minutes by default, and even though I could set the overall timeout to a longer value (using the –wait flag, and specifying a number of minutes) I often forgot that the task was running and found myself forgetting to watch the terminal window. What I really wanted was something that would notify once the build had completed successfully (or erroneously).

So, during one of the package builds (~25 minutes in this case, if I remember correctly) I put together the basis for a new SFDX plugin that I could run to monitor the latest package build request, and then ping up a desktop notification when it had completed.

I was actually on the line-up for the (now postponed) CzechDreamin’ 2020, with a talk titled “Take your SFDX Plugins to the Next Level”. The talk covers many ways to interact with SFDX plugins other than via the CLI, and one of the topics included was the use of the node-notifier npm module to create native desktop notifications, and so I put this to good use.

You can very easily support basic (and more advanced) notifications with node-notifier for Mac, Linux and Windows environments; here’s some sample code (similar to that used in my plugin);

First import node-notifier (after installing it with npm/yarn)

import * as notifier from 'node-notifier'

Then to use it have code similar to this;

notifier.notify({
 'title': 'Latest Packaging Version Creation Complete',
 'subtitle': ‘Success’,
 'message': SubscriberPackageVersionId: ' + res.SubscriberPackageVersionId
 'icon': iconPath,
 'sound': true,
 'timeout': 30
 });

This results in this type of experience;

The source code (with little over 100 lines of actual logic) can be found in the github repo, and the plugin can be installed as an SFDX CLI plugin and run with the following commands;

$ sfdx plugins:install sf-package-version-checker
$ 
$ sfdx pkgvsn:monitor