Retrieving Data

To pull data from Salesforce, each RestObject provides a static retrieve function.

SObject.retrieve(qry, opts?)

import { Account } from './generated';

const accounts = await Account.retrieve(
  'SELECT Id, Name FROM Account LIMIT 1'
);

//using query builder (recommended)
const accounts = await Account.retrieve(f => ({
    select: f.select('id','name'),
    limit: 1
}));

// explicitly setting the Rest client
const accounts = await Account.retrieve(
  'SELECT Id, Name FROM Account LIMIT 1',
  { restInstance: someOtherOrg }
);

It is highly recommended that you use the SOQL builder to construct queries!

Opts

Key

Type

Description

restInstance

Rest

The Rest client to retrieve data from. If not set, "default" client is used. See Connecting with Salesforce

allRows

boolean

Include deleted or achieved records. Defaulted to false. See queryAll.

useComposite

boolean

Experimental! Uses the composite API to reduce the number of queries and in theory offer better performance. NOTE: It seems Salesforce has started throttling queries made this way and thus it is not recommended to use this setting at this time.

Last updated

Was this helpful?