Skip to content

Commit

Permalink
Fix bug with bulk api's job
Browse files Browse the repository at this point in the history
jsforce upgrade also upgraded an xml library which apparently made an object which did not inherit from object, so hasOwnProperty did not exist

Also added try catch in case this fails it will no longer blow up the universe
  • Loading branch information
paustint committed Dec 25, 2023
1 parent ced13de commit c63bd9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function getFieldValues(record: any, options: RecordToApexOptions): [string, Fie
return fields
.filter(
(field) =>
Object.hasOwnProperty.call(record, field) &&
field in record &&
!isObject(record[field]) &&
(includeNullFields || record[field] !== null) &&
(includeBooleanIfFalse || !isBoolean(record[field] || record[field]))
Expand Down
59 changes: 32 additions & 27 deletions libs/shared/utils/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,35 +422,40 @@ export function isValidDate(date: Date) {
export function bulkApiEnsureTyped(job: BulkJobBatchInfo | BulkJobBatchInfoUntyped): BulkJobBatchInfo;
export function bulkApiEnsureTyped(job: BulkJob | BulkJobUntyped): BulkJob;
export function bulkApiEnsureTyped(job: any | any): BulkJob | BulkJobBatchInfo {
if (!isObject(job)) {
try {
if (!isObject(job)) {
return job as BulkJob | BulkJobBatchInfo;
}
const numberTypes = [
'apexProcessingTime',
'apiActiveProcessingTime',
'apiVersion',
'numberBatchesCompleted',
'numberBatchesFailed',
'numberBatchesInProgress',
'numberBatchesQueued',
'numberBatchesTotal',
'numberRecordsFailed',
'numberRecordsProcessed',
'numberRetries',
'totalProcessingTime',
];
if (job['$']) {
job['$'] = undefined;
}
if (job['@xmlns']) {
job['@xmlns'] = undefined;
}

numberTypes.forEach((prop) => {
if (prop in job && typeof job[prop] === 'string') {
job[prop] = Number(job[prop]);
}
});
return job as BulkJob | BulkJobBatchInfo;
} catch (ex) {
return job as BulkJob | BulkJobBatchInfo;
}
const numberTypes = [
'apexProcessingTime',
'apiActiveProcessingTime',
'apiVersion',
'numberBatchesCompleted',
'numberBatchesFailed',
'numberBatchesInProgress',
'numberBatchesQueued',
'numberBatchesTotal',
'numberRecordsFailed',
'numberRecordsProcessed',
'numberRetries',
'totalProcessingTime',
];
if (job['$']) {
job['$'] = undefined;
}
if (job['@xmlns']) {
job['@xmlns'] = undefined;
}
numberTypes.forEach((prop) => {
if (job.hasOwnProperty(prop) && typeof job[prop] === 'string') {
job[prop] = Number(job[prop]);
}
});
return job as BulkJob | BulkJobBatchInfo;
}

export function getHttpMethod(type: InsertUpdateUpsertDelete): HttpMethod {
Expand Down

0 comments on commit c63bd9a

Please sign in to comment.