soql example with rest api
时间: 2023-02-05 17:35:21 浏览: 57
好的。SOQL (Salesforce Object Query Language) 是 Salesforce 的一种查询语言,用于从 Salesforce 中的对象检索数据。您可以使用 REST API 在 Salesforce 中执行 SOQL 查询。
下面是一个使用 REST API 调用执行 SOQL 查询的示例:
```
// Replace <YOUR_INSTANCE_URL> and <YOUR_ACCESS_TOKEN> with your own values
const instanceUrl = '<YOUR_INSTANCE_URL>';
const accessToken = '<YOUR_ACCESS_TOKEN>';
// Set the query for the SOQL request
const query = 'SELECT Id, Name FROM Account LIMIT 10';
// Set the options for the request
const options = {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + accessToken,
'Content-Type': 'application/json'
}
};
// Execute the SOQL query using the REST API
fetch(`${instanceUrl}/services/data/v50.0/query?q=${query}`, options)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
```
上面的示例使用 `fetch()` 函数发出一个 HTTP GET 请求,将 `query` 参数作为查询字符串传递给 REST API。然后使用 `response.json()` 解析响应并将其打印到控制台。
希望这能帮到您!