Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
// DELETING
Util.writeLog(`[${org.alias}] Deleting records from [${sObjName}]`, LogLevel.TRACE);
org.conn.bulk.pollTimeout = org.settings.pollingTimeout;
// LEARNING: Deleting sObject records in bulk
org.conn.sobject(sObjName)
.find({ CreatedDate: { $lte: Date.TOMORROW } })
.destroy(sObjName)
.then((results: RecordResult[]) => {
let totalSuccess: number = 0;
let totalFailures: number = 0;
results.forEach((result: any) => {
if (result.success) {
totalSuccess++;
} else {
if ((result.errors.length === 1) && (result.errors[0] === "ENTITY_IS_DELETED:entity is deleted:--")) {
// Ignore error
} else {
totalFailures++;
msg = `*** [${org.alias}] Error deleting [${sObjName}] records. ${result.errors.join(", ")}`;
Util.writeLog(msg, LogLevel.ERROR);
}
}