Skip to main content

Salesforce Data Loads from the Command Line

Whether it's creating, updating or deleting records, it seems like we're constantly being asked to do data loads. Trouble is, that this takes away from our core project tasks. There must be a faster way...

Use Case: Move all accounts owned by one user to another user.

Export Data from the Command Line

The first step in loading data is to prepare the import file. Sometimes we are given a nicely formatted import file, but let's pretend you need to pull the data out of Salesforce first.

In our scenario, we need to export the accounts that need to be moved. To do this, we need to get the Id of the user who currently owns the accounts.

You'll notice that this command starts with soql instead of sfdx force:data:soql:query --query. That is because I have set soql as an alias for the sfdx query command. Check out my other post on SOQL from the Command Line for more details on this technique.

Now that we have the Id of the user who currently owns the accounts, let's get the accounts we need to move over.

Notice that I've added -r csv > chatty_accounts_to_move.csv to the end of this command. This will output the query as a csv and the > symbol will direct the output to a file named chatty_accounts_to_move.csv

This file does not need to exist yet. If it does not exist, the command will create it for you. Be careful though because if it does exist, this command will overwrite the file.

Import Data from the Command Line

After you have exported your data and updated the csv to have the new owner's Id, you're ready to upload it to Salesforce. You can do that by running: 

The force:data:bulk:upsert command is a favorite of mine because it's so easy to use. In this example we are upserting accounts and using the Id column to identify the records. It is possible to use an External Id field here and upsert records based on a field that is not Id!

We are also passing the csv file into this command along with the alias of the org we want to import the data to. The --wait parameter allows you to define the number of minutes the CLI should wait for the upsert to complete. I typically just use 10 each time because the CLI will respond as soon as the upsert finishes.

Continued Learning

While exporting and importing data from the command line is faster than having to open up another application each time, there is a way to do this even faster. Check out Manipulate Salesforce Data from the Command Line to learn how you could do this in a single command.

If you're still getting used to the Salesforce CLI, I recommend checking out some of these links:


Popular posts from this blog

Salesforce Lighting Migration: Plan for Success

In April 2018, I led the Salesforce Lightning Migration at Postmates. This is how I would do it over again if I could.

Define Goals The goals of a Lightning Migration are: Enable Lightning ExperienceConfigure Lightning ExperienceDocument all Salesforce processesCreate training and support materialsLightning Experience is adopted Easy enough right? Let's go though the plan to see how we accomplish each one. Enable Lightning Experience Just turn it on right? Well, kinda.
Although it may be controversial, I recommend turning it on and hiding the option from all users. This can be done by removing the Lightning Experience User permission from your custom profiles. 
And yes, turn it on in production
Why? You're going to turn it on anyway. Salesforce has declared this as the path forward, so you either turn it on now or wait until they flip the switch for you.
Plus, turning this on ahead of time will make deploying from a sandbox much easier. Trust me.
Goal #1 Enable Lightning Exp…

Lightning Record Pages for Ultimate Productivity

Salesforce Lightning Experience provides so many configuration options that it's hard to know where to start. I'd like to share how I build Lightning Record Pages to help get you started.

I create Lightning Record Pages with 3 key concepts in mind:
Consistent designSpeedEverything they need is in one place Building a Lightning Record Page that delivers these concepts will enable your users to have ultimate productivity. Let's Take a Look: Account Lightning Record Page Contact Lightning Record Page Opportunity Lightning Record Page Notice Anything? They all look the same. I know, that's on purpose 🤓

Here are a few key similarities:

1. Activity and Chatter are in the same place

It's common to develop a "muscle memory" when doing repetitive tasks like logging calls or posting to Chatter.

⚡ Put components used for repetitive tasks in the same place. ⚡
2. Record Details load first
Salesforce does not recommend this because it hurts page load time. I used to load …

Why Users Switch Back to Classic

When rolling out Lightning Experience, people are constantly switching back to Classic. Even after the initial rollout it's common to see people switching back and forth.

The most common reasons someone switches back to Classic are:
Classic loads fasterTheir workflow is slower in LightningThey just don't want to switch to Lightning Overcoming these objections will be key to a successful rollout. Let's dive into each one in more detail. Classic Loads Faster It does. 😢
And when you hear someone complain about this, take their side.  Agree with them.  Make that ironic joke, "haha, yeah Classic is faster than Lightning". ⚡⚡⚡
Then overcome this by highlighting how their overall workflow is faster in Lightning.
The page takes longer to load because each page is made up of many components. Once it has loaded, someone can complete their task on a single page. Their Workflow is Slower in Lightning It probably is. At least until they get used to it. 👨‍💻👩‍💻
Similarly, i…