-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateSalesforceObject.js
33 lines (28 loc) · 1.06 KB
/
updateSalesforceObject.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
/**
* Update a record in an SF CRM object
* @param {string} type SF CRM object API name, i.e. 'Contact', 'ema_CustomObject__c'
* @param {string} sfObjId SF CRM record id, i.e. 003... ContactKey
* @param {object} props An object containing the fields to update and their new values
* @returns {object | undefined}
*/
function updateSalesforceObject(type, sfObjId, props) {
if (!props || !sfObjId || !type) {
return undefined
}
var updateData = []
for (var key in props) {
updateData.push(key)
updateData.push(props[key])
}
var updateSFObject = "";
updateSFObject += "\%\%[";
updateSFObject += "set @SFUpdateResults = UpdateSingleSalesforceObject('" + type + "',";
updateSFObject += "'" + sfObjId + "','" + updateData.join("','") + "'";
updateSFObject += ")";
updateSFObject += "output(concat(@SFUpdateResults))";
updateSFObject += "]\%\%";
var execUpdate = Platform.Function.TreatAsContent(updateSFObject)
return Number(execUpdate) > 0
? { success: type + ' updated' }
: { error: 'Error updating SF record' }
}