Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scratch): add org-capitalize-record-types #1020

Merged
merged 6 commits into from
Jan 22, 2024

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Jan 16, 2024

What does this PR do?

Adds a new org-capitalize-record-types config var to allow to users to choose whether to capitalize record types defined in a scratch org definition file when creating the org.

If the config var isn't set it will still capitalize record types but will emit a warning for users to set the config var to true (we'll stop capitalization in a next major release of sfdx-core, will sync with CLI deprecation policy).

Testing

Expected behaviour:

  • no config var: emit warning and capitalize record types
  • org-capitalize-record-types=false: no warning, don't capitalize
  • org-capitalize-record-types=true: no warning, capitalize.

also, try making org create scratch timeout when org is ready but before it deploy settings to confirm sf org resume scratch also respects the config var.

Setup

  1. Checkout this branch and yarn link it into plugin-org and plugin-settings
  2. clone dreamhouse and update the org def. file with this:
{
    "orgName": "Dreamhouse",
    "edition": "Developer",
    "features": ["Walkthroughs", "EnableSetPasswordInApi"],
    "objectSettings": {
      "case": {
        "defaultRecordType": "svc_Technical_Support",
        "sharingModel": "private"
      }
    },
    "settings": {
        "lightningExperienceSettings": {
            "enableS1DesktopEnabled": true
        },
        "mobileSettings": {
            "enableS1EncryptedStoragePref2": false
        }
    }
}

Turn off record type capitalization

  1. set config var: sf config set org-capitalize-record-types=false -g
  2. create org: sf org create scratch -d -f config/project-scratch-def.json -a dreamhouse --duration-days 1
  3. check that svc_Technical_Support record type isn't capitalized:
    UI
    sf org open --path lightning/setup/ObjectManager/Case/RecordTypes/view:

Screenshot 2024-01-18 at 12 51 12

CLI
sf sobject describe --sobject Case --json | jq '.result.recordTypeInfos'

[
  {
    "active": true,
    "available": false,
    "defaultRecordTypeMapping": false,
    "developerName": "svc_Technical_Support", // HERE
    "master": false,
    "name": "svc_Technical_Support",
    "recordTypeId": "012DE000008EWEVYA4",
    "urls": {
      "layout": "/services/data/v59.0/sobjects/Case/describe/layouts/012DE000008EWEVYA4"
    }
  },
  {
    "active": true,
    "available": true,
    "defaultRecordTypeMapping": true,
    "developerName": "Master",
    "master": true,
    "name": "Master",
    "recordTypeId": "012000000000000AAA",
    "urls": {
      "layout": "/services/data/v59.0/sobjects/Case/describe/layouts/012000000000000AAA"
    }
  }
]

NUTs

There are some NUTs in plugin-org:
salesforcecli/plugin-org#935

a few try to run config unset org-capitalize-record-types using the global sf installed in the NUT job, so those will fail until:

  1. this PR gets merged
  2. plugin-org and plugin-settings get sfdx-core bumped to include this change
  3. both plugins are included in the nightly channel (NUT jobs get nightly sf).

What issues does this PR fix or reference?

forcedotcom/cli#2633
@W-14750427@

@cristiand391 cristiand391 marked this pull request as ready for review January 18, 2024 15:55
@cristiand391 cristiand391 requested a review from a team as a code owner January 18, 2024 15:55
# noCapitalizeRecordTypeConfigVar

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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this warning will be visible to both projects using sfdx-core and the CLI.

For lib users, I wanted to make this an object option rather than the config (that way the config var would live in plugin-org) but decided against it (more about that below).


async function getCapitalizeRecordTypesConfig(): Promise<boolean | undefined> {
const configAgg = await ConfigAggregator.create();
const value = configAgg.getInfo('org-capitalize-record-types').value as string | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type of value is AnyJson | undefined, at runtime we have 2 possible options:

  1. a string containing true or false. NOTE this is always a string, not a boolean
    2 undefined

if it's undefined then we want to return that so SettingsGenerator knows there's no config var and emits the warning.

if not undefined we cast it to boolean and return it.

businessProcessName = upperFirst(defaultRecordType) + 'Process';
businessProcessName = capitalizeBusinessProcess
? `${upperFirst(defaultRecordType)}Process`
: `${defaultRecordType}Process`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't in the scope of the inv. we got but it's the same behavior (for the listed 4 objects above) so I made this follow the config var too.

messages/config.md Outdated Show resolved Hide resolved
messages/envVars.md Outdated Show resolved Hide resolved
src/org/scratchOrgSettingsGenerator.ts Show resolved Hide resolved
@shetzel
Copy link
Contributor

shetzel commented Jan 22, 2024

QA:
✅ without config var, see the warning and the record is capitalized
✅ with config var set to false, no warning and the record is not capitalized
✅ with config var set to true, no warning and the record is capitalized
✅ with config var set to false, org create async, org resume, no warning and record is not capitalized
✅ without config var, org create async, org resume, see warnings for both commands, and record is capitalized

@shetzel shetzel merged commit 2f18baa into main Jan 22, 2024
66 checks passed
@shetzel shetzel deleted the cd/record-type-uppercase-config branch January 22, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants