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 target-org 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

Methods

  • 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: string | AuthInfo

      The AuthInfo for the username to add.

    Returns Promise<Org>

  • Check that this org is a scratch org by asking the dev hub if it knows about it.

    Throws SfError{ name: 'NotADevHubError' } Not a Dev Hub.

    Throws SfError{ name: 'NoResultsError' } No results.

    Parameters

    • Optional devHubUsernameOrAlias: string

      The username or alias of the dev hub org.

    Returns Promise<Partial<AuthFields>>

  • Clean all data files in the org's data path. Usually /.sfdx/orgs/.

    Parameters

    • Optional orgDataPath: string

      A relative path other than "orgs/".

    • throwWhenRemoveFails: boolean = false

      Should the remove org operations throw an error on failure?

    Returns Promise<void>

  • Parameters

    • sandboxReq: SandboxRequest

      SandboxRequest options to create the sandbox with

    • sourceSandboxName: string

      the name of the sandbox that your new sandbox will be based on

    • options: {
          interval?: Duration;
          wait?: Duration;
      }

      Wait: The amount of time to wait before timing out, defaults to 0, Interval: The time interval between polling defaults to 30 seconds

      • Optional interval?: Duration
      • Optional wait?: Duration

    Returns Promise<SandboxProcessObject>

    the newly created sandbox process object

  • create a sandbox from a production org 'this' needs to be a production org with sandbox licenses available

    Parameters

    • sandboxReq: SandboxRequest

      SandboxRequest options to create the sandbox with

    • options: {
          async?: boolean;
          interval?: Duration;
          wait?: Duration;
      } = ...

      Wait: The amount of time to wait before timing out, Interval: The time interval between polling

      • Optional async?: boolean
      • Optional interval?: Duration
      • Optional wait?: Duration

    Returns Promise<SandboxProcessObject>

  • Will delete 'this' instance remotely and any files locally

    Returns Promise<void>

  • Will delete 'this' instance remotely and any files locally

    Parameters

    • controllingOrg: string | Org

      username or Org that 'this.devhub' or 'this.production' refers to. AKA a DevHub for a scratch org, or a Production Org for a sandbox

    Returns Promise<void>

  • 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

    • 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>

  • Returns true if the org is a sandbox.

    Use a cached value. If the cached value is not set, then check Organization.IsSandbox == true && Organization.TrialExpirationDate == null using Org.retrieveOrganizationInformation.

    Returns Promise<boolean>

  • Returns true if the org is a scratch org.

    Use a cached value. If the cached value is not set, then check Organization.IsSandbox == true && Organization.TrialExpirationDate != null using Org.retrieveOrganizationInformation.

    Returns Promise<boolean>

  • Returns the JSForce connection for the org. side effect: If you pass it an apiVersion, it will set it on the Org so that future calls to getConnection() will also use that version.

    Parameters

    • Optional apiVersion: string

      The API version to use for the connection.

    Returns Connection<Schema>

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

    Returns Promise<undefined | Org>

  • Returns an org field. Returns undefined if the field is not set or invalid.

    Type Parameters

    • T = AnyJson

    Parameters

    Returns T

  • Returns the orgId for this org.

    Returns string

  • get the sandbox config for the given orgId

    Parameters

    • orgId: string

      {string} orgId of the sandbox

    Returns Promise<Nullable<SandboxFields>>

  • Returns the admin username used to create the org.

    Returns undefined | string

  • 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

  • Check if org is a sandbox org by checking its SandboxOrgConfig.

    Returns Promise<boolean>

  • Returns true if the org is a scratch org.

    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 scratch org. If you need accuracy, use the Org.determineIfScratch method.

    Returns boolean

  • Reads and returns the content of all user auth files for this org as an array.

    Returns Promise<AuthInfo[]>

  • Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.

    Returns Promise<void>

  • Refresh (update) a sandbox from a production org. 'this' needs to be a production org with sandbox licenses available

    Parameters

    • sandboxInfo: SandboxInfo

      SandboxInfo to update the sandbox with

    • options: {
          async?: boolean;
          interval?: Duration;
          wait?: Duration;
      } = ...

      Wait: The amount of time to wait before timing out, Interval: The time interval between polling

      • Optional async?: boolean
      • Optional interval?: Duration
      • Optional wait?: Duration

    Returns Promise<SandboxProcessObject>

  • Cleans up all org related artifacts including users, sandbox config (if a sandbox), source tracking files, and auth file.

    Parameters

    • throwWhenRemoveFails: boolean = false

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

    Returns Promise<void>

  • Removes a username from the user config for this object. For convenience this object is returned.

    Throws SfError{ name: 'MissingAuthInfoError' } Auth info is missing.

    Parameters

    • auth: string | AuthInfo

      The AuthInfo containing the username to remove.

    Returns Promise<Org>

  • Resume a sandbox create or refresh from a production org. this needs to be a production org with sandbox licenses available.

    Parameters

    • resumeSandboxRequest: ResumeSandboxRequest

      SandboxRequest options to create/refresh the sandbox with

    • options: {
          async?: boolean;
          interval?: Duration;
          wait?: Duration;
      } = ...

      Wait: The amount of time to wait (default: 0 minutes) before timing out, Interval: The time interval (default: 30 seconds) between polling

      • Optional async?: boolean
      • Optional interval?: Duration
      • Optional wait?: Duration

    Returns Promise<SandboxProcessObject>

  • 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>

  • Reports sandbox org creation status. If the org is ready, authenticates to the org.

    Parameters

    • sandboxname: string
    • options: {
          interval?: Duration;
          wait?: Duration;
      }

      Wait: The amount of time to wait before timing out, Interval: The time interval between polling

      • Optional interval?: Duration
      • Optional wait?: Duration

    Returns Promise<SandboxProcessObject>

    the sandbox process object

  • set the sandbox config related to this given org

    Parameters

    • orgId: string

      {string} orgId of the sandbox

    • config: SandboxFields

      {SandboxFields} config of the sandbox

    Returns Promise<Org>

  • Set the tracking property on the org's auth file

    Parameters

    • value: boolean

      true or false (whether the org should use source tracking or not)

    Returns Promise<void>

  • Returns Promise<boolean>

  • Returns true if the org uses source tracking. Side effect: updates files where the property doesn't currently exist

    Returns Promise<boolean>