Created
August 29, 2018 16:04
-
-
Save JesseRWeigel/30fbe8d4c6db95c92adfb7292bf6b651 to your computer and use it in GitHub Desktop.
Sample jsforce code to create a new record in Salesforce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]' | |
}, | |
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