Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

Random handy CumulusCI notes

13 Jul 2021 🔖 salesforce
💬 EN

Table of Contents

Below are some miscellaneous Salesforce scratch org / packaging / SFDX / CumulusCI / VSCode / Git notes I don’t want to forget.

My colleague set up a Git repository with the following structure:

.
├── .github
│   └── PULL_REQUEST_TEMPLATE.md
├── datasets
│   └── mapping.yml
├── force-app
│   └── main
│       └── default
│           └── objects
│               └── Legacy_Custom_Object__c
│                   ├── fields
│                   │   ├── Field_One__c.field-meta.xml
│                   │   └── Field_Two__c.field-meta.xml
│                   ├── listViews
│                   │   └── All.listView-meta.xml
│                   ├── recordTypes
│                   │   ├── Type_One.recordType-meta.xml
│                   │   └── Type_Two.recordType-meta.xml
│                   └── Legacy_Custom_Object__c.object-meta.xml
├── orgs
│   ├── beta.json
│   ├── dev.json
│   ├── feature.json
│   └── release.json
├── robot
│   └── OurPackageName
│       └── tests
│           └── create_contact.robot
├── .gitignore
├── cumulusci.yml
├── README.md
└── sfdx-project.json

And the following .gitignore:

# Salesforce / SFDX / CCI
.cci
.sfdx
/src.orig
/src

# Python
*.pyc
__pycache__

# Robot Framework results
robot/OurPackageName/results/

# Editors
*.sublime-project
*.sublime-workspace
.vscode
.idea
.project
.settings

# Misc
.DS_Store

I did a git clone to my local machine so I could work on it.

All right, what do I do?

VSCode Peacock color theme

Updated /.vscode/settings.json with a nice Peacock color that’ll help me remember what’s what.

Didn’t need to .gitignore the new .vscode folder because it’s already in there. Yay.

Git branch

Used GitHub Desktop to create a new branch newfeature and Publish it to GitHub.

Verified that it appears on GitHub as “even with main.”

Verified that VSCode is showing up with the correct branch selected in my git control panel.

Configure a dev hub username in my local codebase

I created a file /.sfdx/sfdx-config.json whose contents are:

{ "defaultdevhubusername": "my-company-hub-org-nickname" }

Manipulating a Salesforce scratch org

Create a scratch org

In my VSCode terminal, at the root of my repo, run:

`sfdx auth:list`

I see the “hub” in the list for the production org I’m going to want to spin up a scratch from, so that seems promising. Pretty sure I can skip any sort of sfdx force:auth:web:login --setdefaultdevhubusername --setalias my-hub-org command (my-hub-org being an alias for handy use).

Also, since there’s clearly a lot of boilerplate already in the repo, I’m guessing I don’t have to do anything along the lines of sfdx force:project:create --projectname mywork --template standard or, alternatively, cci project init (which is normally the first thing I’d apparently do after git init if I were setting up my own project from scratch, using a source format of sfdx, not mdapi, and ).

The Summit Events docs pointed out that I can confirm this by running the following command:

cci project info

Oh, cute, time to upgrade CCI.

pipx upgrade cumulusci

I ran cci org list and, unsurprisingly, I don’t have any scratch orgs spinning yet.

Time to create one:

cci flow run dev_org --org dev

Took about a minute or two.

This fails with an error of ERROR running force:org:create: This command requires a dev hub org username set either with a flag or by default in the config. Run this command for more information about debugging errors: cci error --help if I didn’t set up sfdx-config.json

Now there’s a scratch org under the dev row of the output of cci org list.

Open the scratch org

Now I’ll open the dev org in my web browser:

cci org browser --org dev

Make and track changes

  1. If I ever needed to retrieve point-and-click changes from the dev scratch org onto my local machine, I could use cci task run list_changes --org dev and cci task run retrieve_changes --org dev to do so.
  2. If I make any changes on my local machine that I want to push to the dev scratch org, I can run cci task run dx_push --org dev.
    • I haven’t tested thoroughly, but it looks like this command might only push changes that are committed to my local git repository, not just ones that are saved to disk on my local machine.
    • Maybe I’m just doing things wrong, but I’m finding the deployment & test-running workflow annoying compared to the way I have coding set up against more traditional sandboxes w/ a package.xml file, so I’ve jumped to coding in Developer Console instead of VSCode for this project (using retrieve_changes when I’m happy), since it’s a small project and not worth my time to fight VSCode over.

When I have things to push to GitHub, I can use ordinary git commands.

Delete org and recreate with dependent packages

Oops, this one needs an internal package, the Education Data Architecture (“EDA”), and the Marketing Cloud Connector in it.

https://cumulusci.readthedocs.io/en/main/cheat_sheet.html

cci org scratch_delete dev

Great, cci org list shows dev as still a row in the table, but nothing there.

In /cumulusci.yml, I added this under the project outermost property, right below its package subproperty and above its git subproperty:

    dependencies:
        - version_id: '1234567890' # Dependency 1:  Corporate internal package
        - github: 'https://github.com/SalesforceFoundation/EDA' # Dependency 2:  EDA
        - namespace: 'et4ae5' # Dependency 3:  MarketingCloud Connector version 230.1
          version: 230.1 

Let’s create it again:

cci flow run dev_org --org dev

Phew – that’s a lot slower – EDA’s a big boy to install. I think last time it might’ve taken 20 minutes?

The org-creation logs ended like this:

?[32m2021-07-08 16:07:15:?[0m [InProgress]: next check in 1 seconds
?[32m2021-07-08 16:07:16:?[0m [Done]
?[32m2021-07-08 16:07:17:?[0m [Success]: Succeeded
?[32m2021-07-08 16:11:51:?[0m ?[31mException in task dependencies.update_dependencies?[0m

<class 'requests.exceptions.RetryError'>: An error occurred while making a request to GitHub: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /repos/SalesforceFoundation/EDA (Caused by ResponseError('too many 401 error responses'))
Run this command for more information about debugging errors: cci error --help

But luckily, opening the org went just fine despite the error at the end of the logs.

I can see hed__Trigger_Handler__c, an EDA object, in the Object Manager in the org’s Setup.

cci org browser --org dev

Open the scratch org manually in a different web browser

Editing custom metadata and switching to classic aren’t working in Firefox from a VSCode-opened browser session, so I need to fire up Chrome and log in manually.

cci org browser --org dev --url-only

I copy the URL displayed & paste it into Chrome.

Tip: Ctrl+Click makes VSCode give me an option to copy rather than open. Keeps me from having to carefully select the URL from beginning to end.

Much better – now I can see the body of https://....lightning.force.com/lightning/setup/CustomMetadata/home.

--- ---