@salesforce/core
    Preparing search index...

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

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

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

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

      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

      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

      • OptionalapiVersion: string

        The API version to use for the connection.

      Returns Connection

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

      Returns Promise<Org | undefined>

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

      Type Parameters

      • T = AnyJson

      Parameters

      Returns T

    • Generate a URL to a metadata UI builder/setup section in an org.

      Bot: open in Agentforce Builder ApexPage: opens page Flow: open in Flow Builder FlexiPage: open in Lightning App Builder CustomObject: open in Object Manager ApexClass: open in Setup -> Apex Classes UI

      if you pass any other metadata type you'll get a path to Lightning App Builder

      Parameters

      • typeName: string
      • file: string

      Returns Promise<string>

      // use SDR resolver:
      import { MetadataResolver } from '@salesforce/source-deploy-retrieve';

      const metadataResolver = new MetadataResolver();
      const components = metadataResolver.getComponentsFromPath(filePath);
      const typeName = components[0]?.type?.name;

      const metadataBuilderUrl = await org.getMetadataUIURL(typeName, filePath);

      Bot | ApexPage | Flow | FlexiPage | CustomObject | ApexClass

      Absolute file path to the metadata file

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

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

    • Executes a GET request on the baseUrl to force an auth refresh. This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.

      This method issues a request using the current access token to check if it is still valid. If the request returns 200, no refresh happens, and we keep the token. If it returns 401, jsforce will request a new token and set it in the connection instance.

      Returns Promise<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

      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

      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

      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>