Skip to content

Instantly share code, notes, and snippets.

@JesseRWeigel
Created August 29, 2018 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseRWeigel/30fbe8d4c6db95c92adfb7292bf6b651 to your computer and use it in GitHub Desktop.
Save JesseRWeigel/30fbe8d4c6db95c92adfb7292bf6b651 to your computer and use it in GitHub Desktop.
Sample jsforce code to create a new record in Salesforce
const conn = new jsforce.Connection({
// you can change loginUrl to connect to sandbox or prerelease env.
loginUrl: 'https://example.my.salesforce.com/'
})
conn.login(username, password, function (err, userInfo) {
if (err) {
return console.error(err)
}
// Now you can get the access token and instance URL information.
// Save them to establish connection next time.
console.log(conn.accessToken)
console.log(conn.instanceUrl)
// logged in user property
console.log('User ID: ' + userInfo.id)
console.log('Org ID: ' + userInfo.organizationId)
// ...
// Single record creation
conn.sobject('Contact').create(
{
FirstName: 'Jane',
LastName: 'Doe',
Email: 'test@test.com'
},
function (err, ret) {
if (err || !ret.success) {
return console.error(err, ret)
}
console.log('Created record id : ' + ret.id)
}
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment