1.1.3 • Published 4 years ago
salesforce-rest-api v1.1.3
salesforce-rest-api
Node.js library for salesforce rest api
Supports 'query records' and the following record methods:
- Create
- Update
- Delete
- Get
In order to set oauth credentials prior to executing the methods there are 2 options:
- Using the setOauth function - then each method execution will use this predfined oauth
- Passing an oauth credentials as an argument in the relevant method (optional)
Install
npm i salesforce-rest-api
Usage
let rest = require('salesforce-rest-api');
rest.setOauth({
accessToken: 'access token value',
instanceUrl: 'instance url value'
});
Create
try {
const response = await rest.createRecord({
type: 'Account',
recordData: {name: 'Gilad'}
});
const newRecordId = response.body.id;
}
catch (err) {
body = err.response.body[0];
//handle error
}
Update
try {
const response = await rest.updateRecord({
type: 'Account',
recordData: {Name: 'Gilad'},
recordId: newRecordId
});
}
catch (err) {
//handle error
}
Delete
try {
const response = await rest.deleteRecord({
type: 'Account',
recordId
});
}
catch (err) {
//handle error
}
Get
Gets a record data
try {
const response = await rest.getRecord({
type: 'AccountInvalid',
recordId
});
const recordId = response.body.Id;
}
catch (err) {
//handle error
}
Query records
Query records using the soql syntax
try {
const response = await rest.queryRecords({soqlQuery: 'SELECT name from Account where name=\'Account1\''});
const records = response.body.records;
}
catch (err) {
//handle error
}