Skip to content

Commit

Permalink
fix: Record Id mapping issue #895
Browse files Browse the repository at this point in the history
  • Loading branch information
hknokh2 committed Oct 24, 2024
1 parent 40acb6d commit 5ba91ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/modules/components/common_components/statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const CONSTANTS = {


__ID_FIELD_NAME: "___Id",
__SOURCE_ID_FIELD_NAME: "___SourceId",
__IS_PROCESSED_FIELD_NAME: "___IsProcessed",

ERRORS_FIELD_NAME: "Errors",
Expand Down
15 changes: 12 additions & 3 deletions src/modules/models/job_models/migrationJobTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@ export default class MigrationJobTask {
// Create separated record sets to Update/Insert /////////////
processedData.clonedToSourceMap.forEach((source, cloned) => {
source[CONSTANTS.__IS_PROCESSED_FIELD_NAME] = typeof source[CONSTANTS.__IS_PROCESSED_FIELD_NAME] == "undefined" ? false : source[CONSTANTS.__IS_PROCESSED_FIELD_NAME];
cloned[CONSTANTS.__SOURCE_ID_FIELD_NAME] = source["Id"];
delete cloned[CONSTANTS.__ID_FIELD_NAME];
let target = self.data.sourceToTargetRecordMap.get(source);
if (target && self.data.task.scriptObject.skipExistingRecords) {
Expand Down Expand Up @@ -2330,19 +2331,26 @@ export default class MigrationJobTask {
records.forEach(record => {
fieldMapping.forEach((newProp, oldProp) => {
if (newProp != oldProp && record.hasOwnProperty(oldProp)) {
record[newProp] = record[oldProp];
if (oldProp != "Id") { // Id => ExternalId__c (Id -> ExternalId__c)
// Id => ExternalId__c
if (oldProp != "Id") {
record[newProp] = record[oldProp];
delete record[oldProp];
} else {
record[newProp] = record[CONSTANTS.__SOURCE_ID_FIELD_NAME];
}
}
});
delete record[CONSTANTS.__SOURCE_ID_FIELD_NAME];
});
return {
targetSObjectName: mapping.targetSObjectName,
records
};
}
}
records.forEach(record => {
delete record[CONSTANTS.__SOURCE_ID_FIELD_NAME];
});
return {
targetSObjectName: sourceSObjectName,
records
Expand All @@ -2360,7 +2368,8 @@ export default class MigrationJobTask {
fieldMapping.forEach((newProp, oldProp) => {
if (newProp != oldProp && record.hasOwnProperty(newProp)) {
if (oldProp != "Id") {
record[oldProp] = record[newProp]; // Id => Externalid__c (ExternalId -> Id)
// Externalid__c => Id
record[oldProp] = record[newProp];
}
delete record[newProp];
}
Expand Down

0 comments on commit 5ba91ab

Please sign in to comment.