vlocode-project - v2.4.3
    Preparing search index...

    Class MatchingKeyService

    Central service that manages matching key fields for SObject types. Matching keys determine which fields uniquely identify a record and are used for looking up existing records during deployment (upsert fields), for generating datapack source keys during export and for building export queries.

    Matching keys are loaded from the following sources; the first source that defines a key for an object wins:

    1. Matching key files (JSON or YAML, matching-keys.json/.yaml by default, see setMatchingKeyFiles)
    2. Consumer-provided export definitions (matchingKeyFields or autoGeneratedMatchingKey)
    3. The org's DRMatchingKey__mdt records
    4. Built-in defaults for standard objects that need a specific key configuration
    5. Bundled export definitions

    When no source defines a key the service falls back to a required unique field, the DeveloperName field or the object's name field. Objects that link to a parent through a master-detail relationship always include the relationship field(s) in their matching key so child records are matched within their parent. When no matching key can be determined at all the object is treated as key-less: records are always inserted on deployment and exported with generated source keys. Top-level datapacks require a matching key which is enforced by the deployment and export flows.

    Index

    Constructors

    Properties

    bundledDefinitions: DatapackExportDefinitionStore = ...

    Bundled definitions used when the consuming application has not loaded the definitions into its own store.

    defaultMatchingKeys: Record<string, string[]> = ...

    Built-in matching key defaults for objects that require a specific key configuration, keyed by normalized (lower case, namespace-less) SObject type. An empty array marks the object as key-less causing records to always be inserted.

    extraMatchingKeyFiles: string[] = []

    Extra matching key files registered through setMatchingKeyFiles.

    fileMatchingKeys?: Promise<Map<string, string[]>>

    Matching keys loaded from matchingKeyFiles; reset when new files are registered.

    logger: Logger
    resolvedKeys: Map<string, Promise<VlocityMatchingKey>> = ...

    Resolved matching keys by normalized SObject type, selected definition scope and schema-fallback behavior.

    salesforce: SalesforceService
    defaultMatchingKeyFiles: string[] = ...

    Default matching key files loaded from the working directory when present.

    Accessors

    Methods

    • Get the matching key fields configured for an object checking each source in order of precedence: matching key files, consumer export definitions, org matching keys, built-in defaults and finally bundled export definitions.

      Parameters

      • sobjectType: string
      • Optionalscope: string

      Returns Promise<readonly string[] | undefined>

      The configured fields or undefined when no source defines a key for the object

    • Get the matching key for the specified SObject type. Resolution is cached per object and selected export-definition scope and schema-fallback behavior.

      Fields configured through one of the matching key sources are validated against the object describe and returned using their API name; configuring a field that does not exist on the object is an error. Master-detail relationship fields of the object are always part of the returned matching key.

      Parameters

      • sobjectType: string

        SObject type with or without (placeholder) namespace prefix

      • Optionalcontext: MatchingKeyContext

        Optional export-definition scope and schema-fallback behavior

      Returns Promise<VlocityMatchingKey>

      The matching key for the object; fields is empty for key-less objects, either explicitly configured as such or because no matching key could be determined.

      When the object does not exist in the target org or a configured field does not exist on the object.

    • Set the matching key files to load in addition to the default matching-keys file in the working directory. Files are JSON or YAML objects mapping an SObject type to an array of matching key field names:

      Product2: [ ProductCode ]
      "%vlocity_namespace%__PriceList__c": [ Name ]

      Matching keys from files take precedence over keys defined in export definitions and in the org; entries in later files override earlier files. Replaces previously set files and resets already resolved matching keys so new resolutions reflect the specified files.

      Parameters

      • ...files: string[]

        Paths of the matching key files to load

      Returns this

    • Validate the fields of a matching key loaded from the org dropping fields that do not exist or are not accessible. Unlike configured matching keys org matching keys are not treated as an error when invalid as they are managed in the org and may reference fields the current user cannot access.

      Parameters

      • sobjectType: string
      • fields: readonly string[]

      Returns Promise<string[]>