0

Query More

by
Published 8 days ago

Fetch the next page of a SOQL result set using the nextRecordsUrl returned by Execute SOQL Query.

Script salesforce Verified

The script

Submitted by hugo989 Bun
Verified 9 days ago
1
//native
2

3
/**
4
 * Query More
5
 * Fetch the next page of a SOQL result set using the nextRecordsUrl returned by Execute SOQL Query.
6
 */
7
export async function main(auth: RT.Salesforce, next_records_url: string) {
8
  const url = new URL(`${auth.instance_url}${next_records_url}`)
9

10
  const response = await fetch(url, {
11
    method: "GET",
12
    headers: {
13
      Authorization: `Bearer ${auth.token}`,
14
      Accept: "application/json",
15
    },
16
  })
17

18
  if (!response.ok) {
19
    throw new Error(`${response.status} ${await response.text()}`)
20
  }
21

22
  return await response.json()
23
}
24