Issue Validating with Scratch Orgs When Working with a Community and State and Country Picklists #553
Labels
area:apex
Highlights the apex functional area of the CLI.
owned by another team
The Salesforce CLI team does not own this work but will pass on the information to the correct team.
Summary
Using a Scratch Org for validation in Pipelines with a project involving a Community and Country and State Picklists, a standard Apex Class created for the Community (MyProfilePageController) has a failing unit test due to an invalid initialization of the User within the Scratch Org. User's Address is set to "US" and once Country and State Picklists are enabled the expectation is for this to be "United States" on the record. This seems to be a recent bug, I had a similar project setup roughly a year ago where all of this was working as expected.
Steps To Reproduce:
Repository to reproduce: sfdx-StateAndCountry-Community-Bug
Reproduction Steps:
sfdx force:org:create -s -f ./config/project-scratch-def.json -a ScratchOrg
sfdx force:source:push
sfdx force:apex:test:run -l RunLocalTests -w 15
Alternatively, use the setupScript.sh within the repo
Expected result
All tests should be passing, this was working as expected in a past project done roughly a year ago.
Actual result
MyProfilePageControllerTest.testSave fails because an Exception is thrown preventing the User Record from being updated thus preventing the System.assert to validate the record was updated.
The Exception is caused by calling Update on the Current User with a Country of "US" but enabling State and Country Picklists expects the Country to be from the picklist (in this case it should be "United States"). This causes a CI/CD process validating with Scratch Orgs to fail if verifying tests are working as expected.
The workaround is to run an Anonymous Apex Script to update the User's Country to be "United States" to then bypass the Exception, but I believe this should not be necessary.
Additional information
User Record:
Test Results:
SFDX CLI Version(to find the version of the CLI engine run sfdx --version): sfdx-cli/7.69.0 darwin-x64 node-v12.18.2
SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)
@oclif/plugin-autocomplete 0.1.5 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.7.10 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/lwc-dev-server 2.2.0
├─ @oclif/plugin-help 2.2.1
└─ @oclif/plugin-update 1.3.9
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-trust 3.0.7 (core)
analytics 1.12.0 (core)
generator 1.1.3 (core)
salesforcedx 49.5.0 (core)
├─ custom-metadata 1.0.8 (core)
├─ salesforcedx-templates 49.2.0 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
└─ salesforce-alm 49.5.0 (core)
sfdx-cli 7.69.0 (core)
OS and version: MacOS Catalina 10.15.6
The text was updated successfully, but these errors were encountered: