3

We are using a Jenfinsfile in Jenkins to execute SFDX commands. The Jenkins user is connected to our Dev Hub.

In one of our builds, we want to create a Customer Portal User, but in a small percentage of cases that create fails because of some asynchronous logic that must complete has not completed. So the simple solution looked like it would be to retry for a few minutes. Note that this works when we don't have to retry.

But we see this sequence...

This added to help debug:

sfdx force:user:display

returns a good expected result (*** replaces some values for security here):

KEY           VALUE
────────────  ──────────────────────────────────────────────────
Access Token  ***
Alias         portal-cveep/master
Id            ***
Instance Url  https://***-dev-ed.cs66.my.salesforce.com/
Login Url     https://CS66.salesforce.com
Org Id        ***
Password      ***
Profile Name  System Administrator
Username      ***

This is the command we want to execute but sometimes fails due to timing:

sfdx force:user:create --definitionfile config/community-user-def.json --json --targetusername ***

with this response:

{
  "status": 1,
  "name": "Error",
  "message": "Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, ***: []",
  "exitCode": 1,
  "commandName": "UserCreateCommand",
  "stack": ***
  "warnings": []
}

Then 30 seconds later (and same result for subsequent retries) we retry:

sfdx force:user:display

with this weird result of "unknown" for some values and no password:

=== User Description
KEY           VALUE
────────────  ──────────────────────────────────────────────────
Access Token  ***
Alias         portal-cveep/master
Id            unknown
Instance Url  https://***-dev-ed.cs66.my.salesforce.com
Login Url     https://CS66.salesforce.com
Org Id        ***
Profile Name  unknown
Username      ***

The retry (and same result for subsequent retries):

sfdx force:user:create --definitionfile config/community-user-def.json --json --targetusername ***

now fails for this new reason:

{
  "status": 1,
  "name": "JWTAuthError",
  "message": "Error authenticating with JWT config due to: invalid assertion",
  "exitCode": 1,
  "commandName": "UserCreateCommand",
  "stack": ***,
  "warnings": []
}

I'm baffled as to why this happens, so any ideas appreciated.

2
  • 1
    I know this is an old post, but are you trying to create a Community User and specifying a Contact ID? force:user:create "creates" Users in two steps: (1) inserts a User with required Fields. Contact ID is NOT a required Field and is not set. Then (2), all optional Fields are updated to the new User. In step (1), if a Community User profile is specified, a new Contact is created. But in step (2), the optional Contact ID is specified and the update fails since Contact ID is not updateable. Mar 7, 2020 at 1:00
  • 1
    I ran into this issue this week myself. Luckily, I could ask a friend what sfdx is doing under the hood. My solution is to use REST API to create the Used then log in via the Contact record via "Log into Community as User" button during development Mar 7, 2020 at 1:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy