0

Execute SOQL Query

by
Published 8 days ago

Run a SOQL query and return matching records. Large result sets are paginated — follow nextRecordsUrl with the Query More action.

Script salesforce Verified

The script

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

3
/**
4
 * Execute SOQL Query
5
 * Run a SOQL query and return matching records. Large result sets are paginated — follow nextRecordsUrl with the Query More action.
6
 */
7
export async function main(auth: RT.Salesforce, query: string) {
8
  const apiVersion = auth.api_version || "v60.0"
9
  const url = new URL(`${auth.instance_url}/services/data/${apiVersion}/query`)
10
  url.searchParams.append("q", query)
11

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

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

24
  return await response.json()
25
}
26