This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathcrud.js
73 lines (66 loc) · 1.89 KB
/
crud.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var nforce = require('../');
var sfuser = process.env.SFUSER;
var sfpass = process.env.SFPASS;
var oauth;
var org = nforce.createConnection({
clientId: '3MVG9rFJvQRVOvk5nd6A4swCyck.4BFLnjFuASqNZmmxzpQSFWSTe6lWQxtF3L5soyVLfjV3yBKkjcePAsPzi',
clientSecret: '9154137956044345875',
redirectUri: 'http://localhost:3000/oauth/_callback'
});
function deleteLead(ld) {
console.log('attempting to delete lead');
org.delete({ sobject: ld, oauth: oauth }, function(err, resp) {
if(err) {
console.error('--> unable to delete lead');
console.error('--> ' + JSON.stringify(err));
throw err;
} else {
console.log('--> lead deleted');
}
});
}
function updateLead(ld) {
console.log('attempting to update lead');
ld.set('Company', 'JJ Inc.');
org.update({ sobject: ld, oauth: oauth }, function(err, resp) {
if(err) {
console.error('--> unable to update lead');
console.error('--> ' + JSON.stringify(err));
throw err;
} else {
console.log('--> lead updated');
deleteLead(ld);
}
});
}
function insertLead() {
console.log('Attempting to insert lead');
var ld = nforce.createSObject('Lead', {
FirstName: 'Bobby',
LastName: 'Tester',
Company: 'ABC Widgets',
Email: '[email protected]'
});
org.insert({ sobject: ld, oauth: oauth }, function(err, resp) {
if(err) {
console.error('--> unable to insert lead');
console.error('--> ' + JSON.stringify(err));
throw err;
} else {
console.log('--> lead inserted');
updateLead(ld);
}
});
}
console.log('Authenticating with Salesforce');
org.authenticate({ username: sfuser, password: sfpass}, function(err, resp) {
if(err) {
console.error('--> unable to authenticate to sfdc');
console.error('--> ' + JSON.stringify(err));
throw err;
} else {
console.log('--> authenticated!');
oauth = resp;
insertLead();
}
});