Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Org

Provides a way to manage a locally authenticated Org.

See AuthInfo

See Connection

See Aliases

See Config

// Email username
const org1: Org = await Org.create({ aliasOrUsername: 'foo@example.com' });
// The defaultusername config property
const org2: Org = await Org.create({});
// Full Connection
const org3: Org = await Org.create({
  connection: await Connection.create({
    authInfo: await AuthInfo.create({ username: 'username' })
  })
});

See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm

Hierarchy

Index

Methods

addUsername

  • Adds a username to the user config for this org. For convenience this object is returned.

    const org: Org = await Org.create({
      connection: await Connection.create({
        authInfo: await AuthInfo.create('foo@example.com')
      })
    });
    const userAuth: AuthInfo = await AuthInfo.create({
      username: 'bar@example.com'
    });
    await org.addUsername(userAuth);

    Parameters

    • auth: AuthInfo | string

      The AuthInfo for the username to add.

    Returns Promise<Org>

checkScratchOrg

  • checkScratchOrg(devHubUsername?: undefined | string): Promise<Partial<AuthFields>>
  • Check that this org is a scratch org by asking the dev hub if it knows about it.

    Throws SfdxError{ name: 'NotADevHub' } Not a Dev Hub.

    Throws SfdxError{ name: 'NoResults' } No results.

    Parameters

    • Optional devHubUsername: undefined | string

      The username of the dev hub org.

    Returns Promise<Partial<AuthFields>>

cleanLocalOrgData

  • cleanLocalOrgData(orgDataPath?: undefined | string, throwWhenRemoveFails?: boolean): Promise<void>
  • Clean all data files in the org's data path. Usually /.sfdx/orgs/.

    Parameters

    • Optional orgDataPath: undefined | string

      A relative path other than "orgs/".

    • Default value throwWhenRemoveFails: boolean = false

      Should the remove org operations throw an error on failure?

    Returns Promise<void>

determineIfDevHubOrg

  • determineIfDevHubOrg(forceServerCheck?: boolean): Promise<boolean>
  • Returns true if the org is a Dev Hub.

    Use a cached value. If the cached value is not set, then check access to the ScratchOrgInfo object to determine if the org is a dev hub.

    Parameters

    • Default value forceServerCheck: boolean = false

      Ignore the cached value and go straight to the server which will be required if the org flips on the dev hub after the value is already cached locally.

    Returns Promise<boolean>

getConfigAggregator

getConnection

Protected getDefaultOptions

getDevHubOrg

  • getDevHubOrg(): Promise<Optional<Org>>
  • Returns the Org object or null if this org is not affiliated with a Dev Hub (according to the local config).

    Returns Promise<Optional<Org>>

getField

  • getField(key: Fields): AnyJson
  • Returns an org field. Returns undefined if the field is not set or invalid.

    Parameters

    Returns AnyJson

getFields

  • getFields(keys: Fields[]): JsonMap
  • Returns a map of requested fields.

    Parameters

    Returns JsonMap

getOrgId

  • getOrgId(): string
  • Returns the orgId for this org.

    Returns string

getSandboxOrgConfigField

  • getSandboxOrgConfigField(field: Fields): Promise<undefined | null | string | number | false | true | JsonMap | JsonArray>
  • Returns an org config field. Returns undefined if the field is not set or invalid.

    Parameters

    Returns Promise<undefined | null | string | number | false | true | JsonMap | JsonArray>

getUsername

  • getUsername(): Optional<string>
  • Returns the admin username used to create the org.

    Returns Optional<string>

Protected init

  • init(): Promise<void>
  • Initialize async components.

    Returns Promise<void>

isDevHubOrg

  • isDevHubOrg(): boolean
  • Returns true if the org is a Dev Hub.

    Note This relies on a cached value in the auth file. If that property is not cached, this method will always return false even if the org is a dev hub. If you need accuracy, use the Org.determineIfDevHubOrg method.

    Returns boolean

readUserAuthFiles

  • readUserAuthFiles(): Promise<AuthInfo[]>
  • Reads and returns the content of all user auth files for this org as an array.

    Returns Promise<AuthInfo[]>

refreshAuth

  • refreshAuth(): Promise<void>
  • Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.

    Returns Promise<void>

remove

  • remove(throwWhenRemoveFails?: boolean): Promise<void>
  • Removes the scratch org config file at $HOME/.sfdx/[name].json, any project level org files, all user auth files for the org, matching default config settings, and any matching aliases.

    Parameters

    • Default value throwWhenRemoveFails: boolean = false

      Determines if the call should throw an error or fail silently.

    Returns Promise<void>

removeUsername

  • removeUsername(auth: AuthInfo | string): Promise<Org>
  • Removes a username from the user config for this object. For convenience this object is returned.

    Throws SfdxError{ name: 'MissingAuthInfo' } Auth info is missing.

    Parameters

    • auth: AuthInfo | string

      The AuthInfo containing the username to remove.

    Returns Promise<Org>

retrieveMaxApiVersion

  • retrieveMaxApiVersion(): Promise<string>
  • Retrieves the highest api version that is supported by the target server instance. If the apiVersion configured for Sfdx is greater than the one returned in this call an api version mismatch occurs. In the case of the CLI that results in a warning.

    Returns Promise<string>

setSandboxOrgConfigField

  • setSandboxOrgConfigField(field: Fields, value: string): Promise<Org>
  • Sets the key/value pair in the sandbox config for this org. For convenience this object is returned.

    Parameters

    Returns Promise<Org>

Static create

  • create<P, T>(this: object, options: P): Promise<T>
  • Asynchronously constructs and initializes a new instance of a concrete subclass with the provided options.

    Type parameters

    • P

    • T: AsyncCreatable<P>

    Parameters

    • this: object
    • options: P

      An options object providing initialization params to the async constructor.

    Returns Promise<T>