Look up records from Salesforce using an more convenient syntax

Hierarchy

  • SalesforceLookupService

Constructors

Properties

logger: Logger
nsService: NamespaceService
queryService: QueryService

Methods

  • Type Parameters

    • T

    Parameters

    • type: string
    • values: undefined | null | ObjectFilter<T>
    • relationshipName: string = ''

    Returns Promise<string>

  • Enables or disables the lookup cache for all lookups performed by this service instance.

    • When enabled, the lookup cache will be used for all lookups unless explicitly disabled using the useCache parameter.
    • When disabled, the lookup cache will not be used for any lookups and the value of the useCache parameter will be ignored.

    Parameters

    • enabled: boolean

      A boolean value indicating whether the lookup cache should be enabled or disabled.

    Returns void

  • Query multiple records based on the where condition. The filter condition can either be a string or a complex filter object.

    Type Parameters

    • T extends object

    • K extends PropertyKey = keyof T

    Parameters

    • type: string

      Name of the SObject type to lookup

    • Optional filter: LookupFilter<T>

      Object filter or Where conditional string, by default the object filter uses and equals comparison (=). A different comparison mode can be specified by prefixing the value with any of these operators:

      • !=: not equals
      • >: greater then
      • <: smaller then
      • ~: like/contains

      Arrays are interpreted as as includes operator. For example:

      lookup('Account', { Name: ['Peter', 'ACME'] }, ['Id', 'Name'] )
      

      will translate to the follow query: select Id, Name from Account where Name includes ('Peter', 'ACME')

      You can also specify multiple filters by passing an array of objects or strings:

      lookup('Account', [{ Name: 'Peter' }, { Name: 'ACME' }], ['Id', 'Name'] )
      

      Which will translate to the follow query: select Id, Name from Account where (Name = 'Peter') or (Name = 'ACME')

    • Optional lookupFields: "all" | K[] | readonly K[]

      fields to lookup on the record, if not field list is provided this function will lookup All fields. Note that the Id field is always included in the results even when no fields are specified, or when a limited set is specified.

    • Optional limit: number

      limit the number of results to lookup, set to 0, null, undefined or false to not limit the lookup results; when specified as 1 returns a single record instead of an array.

    • Optional useCache: boolean

      when true instructs the QueryService to cache the result in case of a cache miss and otherwise retrive the cached response. The default behavhior depends on the

    • Optional cancelToken: CancellationToken

    Returns Promise<QueryResult<T, K>[]>

    See

    QueryService configuration.

  • Lookup records in the target org by their record ID

    Type Parameters

    • K extends PropertyKey

    Parameters

    • id: string
    • Optional lookupFields: "all" | K[]

      Fields to lookup, any fields that do not exist on the object type are ignored. In case all or undefined all fields are retrieved.

    • Optional useCache: boolean

      Optionally use the query cache for retrieving the request records

    • Optional cancelToken: CancellationToken

      Optional cancellation token to signal the method that it should quite as soon as possible.

    Returns Promise<undefined | QueryResult<{
        Id: string;
    }, K>>

    Records in a Map keyed by their record ID

  • Type Parameters

    • K extends PropertyKey

    Parameters

    • ids: Iterable<string>
    • Optional lookupFields: "all" | K[]
    • Optional useCache: boolean
    • Optional cancelToken: CancellationToken

    Returns Promise<Map<string, QueryResult<{
        Id: string;
    }, K>>>

  • Looks up a single record of a given type based on the provided filter.

    Type Parameters

    • T extends object

      The type of the record to lookup.

    • K extends PropertyKey = keyof T

      The type of the lookup fields.

    Parameters

    • type: string

      The type of the record to lookup.

    • Optional filter: LookupFilter<T>

      The filter to apply when looking up the record.

    • Optional lookupFields: "all" | K[]

      The fields to include in the lookup result.

    • Optional useCache: boolean

      Indicates whether to use the cache for the lookup.

    • Optional cancelToken: CancellationToken

      The cancellation token.

    Returns Promise<undefined | QueryResult<T, K>>

    • A promise that resolves to the lookup result.