-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy path_sfOOBOB2CSitesReset.js
More file actions
91 lines (68 loc) · 3.09 KB
/
_sfOOBOB2CSitesReset.js
File metadata and controls
91 lines (68 loc) · 3.09 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
// Initialize required modules
const sfdx = require('sfdx-node/parallel');
/**
* @function _sfOOBOB2CSitesReset
* @description Attempts to reset the OOBO Customer details for each of the B2C Sites associated to the specified customerList
*
* @param {Object} environmentDef Represents the already-validated environment details to use when performing the actions
* @param {String} customerList Represents the customerList for which Sites will be updated
* @returns {Promise} Returns the result of the reset-request for site-specific OOBO properties
*/
module.exports = (environmentDef, customerList) =>
new Promise(async (resolve, reject) => {
// Initialize local variables
let output;
// Initialize the output variable
output = {};
try {
// Retrieve the B2C CustomerList
output.b2cCustomerList = await sfdx.force.data.recordGet({
_quiet: true,
sobjecttype: 'B2C_CustomerList__c',
where: `Name='${customerList}'`
});
// Exit early if the customerList isn't verified
if (!output.b2cCustomerList) { return; }
// Retrieve the sites associated to the current customerList
output.b2cSites = await sfdx.force.data.soqlQuery({
_quiet: true,
query: `SELECT Id, Name FROM B2C_Site__c WHERE Customer_List__c='${output.b2cCustomerList.Id}'`
});
// Was at least one site found?
if (output.b2cSites.totalSize > 0) {
// Create the updates elements
output.b2cSiteUpdates = {};
// If so, then let's default each of the b2cSites
for (let thisSite of output.b2cSites.records) {
// Initialize the siteUpdate output
output.b2cSiteUpdates[thisSite.Name] = {};
// Update the current B2C Site and reset the customerId
output.b2cSiteUpdates[thisSite.Name].customerId = await sfdx.force.data.recordUpdate({
_quiet: true,
sobjecttype: 'B2C_Site__c',
sobjectid: thisSite.Id,
values: 'OOBO_Customer_ID__c=null'
});
// Update the current B2C Site and reset the customerNo
output.b2cSiteUpdates[thisSite.Name].customerNo = await sfdx.force.data.recordUpdate({
_quiet: true,
sobjecttype: 'B2C_Site__c',
sobjectid: thisSite.Id,
values: 'OOBO_Customer_Number__c=null'
});
}
}
// Flag the request as successful
output.success = true;
// Resolve successfully
resolve(output);
} catch (e) {
// Flag the request as failed
output.success = false;
output.error = e;
output.stack = e.stack;
// Reject with an error
reject(output);
}
});