Closed Gurenax closed 6 years ago
Figured out that there's a requestOpts
option.
After executing the following, I was able to insert:
const sobj = nforce.createSObject(sobjectName)
sobj.setExternalId('Id', recordId)
Object.entries(recordDataWithID).map(([key, value]) => {
sobj.set(key, value)
})
org.upsert(
{
sobject: sobj,
oauth: oauth,
requestOpts: {
method: 'POST'
}
},
(error, response) => {
if (!error) {
console.log(response)
} else {
console.error('Error: ', error)
}
}
)
But after executing it the second time in which I wanted to Upsert for an update, I am now getting the error:
Error: { Error: HTTP Method 'POST' not allowed. Allowed are GET,HEAD,PATCH,DELETE
Figured out a solution! I can just set a condition using my recordId parameter:
const sobj = nforce.createSObject(sobjectName)
sobj.setExternalId('Id', recordId)
Object.entries(recordDataWithID).map(([key, value]) => {
sobj.set(key, value)
})
org.upsert(
{
sobject: sobj,
oauth: oauth,
requestOpts: {
method: !recordId ? 'POST' : 'PATCH'
}
},
(error, response) => {
if (!error) {
console.log(response)
} else {
console.error('Error: ', error)
}
}
)
I hope this information can help someone else. Cheers!
After executing upsert, I receive the error:
The
Connection.prototype.upsert
function does specify PATCH in opts.method:My suggestion is to change
opts.method
to POST. Not unless there's a workaround?