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

Unexpected behavior. Perhaps a bug. #3043

Closed
codefriar opened this issue Oct 4, 2024 · 5 comments
Closed

Unexpected behavior. Perhaps a bug. #3043

codefriar opened this issue Oct 4, 2024 · 5 comments
Labels
more information required Issue requires more information or a response from the customer

Comments

@codefriar
Copy link

Summary

I'm developing a sf extension.
As part of this, I need to write a file. One of the required flags of my command is -o the target alias. Because there could potentially be multiple orgs in play, I want to name this file based on the Org's alias. Investigation into the public properties and methods led me to believe that the following code snippet would return the org's alias.

    const orgName = orgAlias.getField(Fields.ALIAS);

This however, results in orgName being undefined.

I'm invoking this command via:

sf myNamespace myCommand -o myAlias

where myAlias is a known alias of an org and can be seen in sf org list.

Expected result

I expect that the Org object returned from flags with a type of requiredOrg would return the known alias of the org.

Actual result

The code snipped above, results in an undefined value being returned.

Additional information

I am able to retrieve the orgId, but that's less human readable / understandable, and would love to know how to reliably get the local org alias for the specified org.

System Information

zsh on mac os Sonoma, latest.

{
  "architecture": "darwin-arm64",
  "cliVersion": "@salesforce/cli/2.59.6",
  "nodeVersion": "node-v20.17.0",
  "osVersion": "Darwin 23.6.0",
  "rootPath": "/Users/kevinpoorman/.volta/tools/image/packages/@salesforce/cli/lib/node_modules/@salesforce/cli",
  "shell": "zsh",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.2.3 (core)",
    "@oclif/plugin-commands 4.0.14 (core)",
    "@oclif/plugin-help 6.2.11 (core)",
    "@oclif/plugin-not-found 3.2.20 (core)",
    "@oclif/plugin-plugins 5.4.7 (core)",
    "@oclif/plugin-search 1.2.8 (core)",
    "@oclif/plugin-update 4.5.6 (core)",
    "@oclif/plugin-version 2.2.12 (core)",
    "@oclif/plugin-warn-if-update-available 3.1.15 (core)",
    "@oclif/plugin-which 3.2.13 (core)",
    "@salesforce/cli 2.59.6 (core)",
    "apex 3.4.9 (core)",
    "api 1.2.1 (core)",
    "auth 3.6.56 (core)",
    "data 3.6.5 (core)",
    "deploy-retrieve 3.12.7 (core)",
    "dev 2.4.2 (user) published 37 days ago (Mon Aug 26 2024)",
    "info 3.4.6 (core)",
    "limits 3.3.30 (core)",
    "marketplace 1.2.25 (core)",
    "org 4.5.8 (core)",
    "packaging 2.8.4 (core)",
    "schema 3.3.29 (core)",
    "settings 2.3.19 (core)",
    "sobject 1.4.35 (core)",
    "source 3.5.19 (core)",
    "telemetry 3.6.12 (core)",
    "templates 56.3.18 (core)",
    "trust 3.7.27 (core)",
    "user 3.5.29 (core)",
    "@salesforce/sfdx-scanner 4.5.0 (user) published 37 days ago (Tue Aug 27 2024) (latest is 4.6.0)",
    "bah-toolkit 1.0.0 (link) /Users/kevinpoorman/src/bah-toolkit",
    "sfdx-git-delta 5.45.0 (user) published 13 days ago (Fri Sep 20 2024) (latest is 5.46.0)"
  ]
}
@codefriar codefriar added the investigating We're actively investigating this issue label Oct 4, 2024
Copy link

github-actions bot commented Oct 4, 2024

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

Copy link

github-actions bot commented Oct 4, 2024

Hello @codefriar 👋 None of the versions of sf you shared match the latest release.

Shared: 2.59.6
Latest: 2.60.13

Update to the latest version of Salesforce CLI (docs) and confirm that you're still seeing your issue.
You can also try the rc and nightly releases! (docs)

After updating, share the full output of sf version --verbose --json

@github-actions github-actions bot added more information required Issue requires more information or a response from the customer and removed investigating We're actively investigating this issue labels Oct 4, 2024
@mdonnalley
Copy link
Contributor

mdonnalley commented Oct 4, 2024

@codefriar I would suggest using StateAggregator from sfdx-core for what you need

Off the top of my head, you'd do something like this:

import { StageAggregator } from '@salesforce/core'; 
const stateAggregator = await StateAggregator.getInstance();
const username = stateAggregator.aliases.resolveUsername(orgAlias);

@codefriar
Copy link
Author

@mdonnalley - Appreciate the assist. Slight tweak to your suggestion from .resolveUsername() to .resolveAlias(orgAlias.getUsername()) works great.

@codefriar
Copy link
Author

@mdonnalley - I want to pass on kudos to the team for the pretty well documented cli libraries.

If I may make one request. File level headers explaining what a StateAggregator is would be a nice to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more information required Issue requires more information or a response from the customer
Projects
None yet
Development

No branches or pull requests

2 participants