Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hknokh committed Sep 30, 2022
1 parent 414bd1b commit aa61b68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sfdmu",
"description": "The Salesforce Data Loader SFDX Plugin (SFDMU) will help you to populate your org (scratch / dev / sandbox / production) with data imported from another org or CSV files. It supports all important CRUD operations (Insert/Update/Upsert/Delete) also for multiple related sObjects.",
"version": "4.16.10",
"version": "4.17.0",
"author": "Haim Knokh",
"bugs": "https://github.com/forcedotcom/SFDX-Data-Move-Utility/issues",
"dependencies": {
Expand Down Expand Up @@ -91,4 +91,4 @@
"build": "tsc -b",
"typedoc-sfdmu-run-addons": "typedoc --options typedoc-sfdmu-run-addons.json"
}
}
}
8 changes: 7 additions & 1 deletion src/modules/models/script_models/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default class Script implements IAppScript, ISfdmuRunScript {
@Type(() => ScriptObject)
objects: ScriptObject[] = new Array<ScriptObject>();

excludedObjects: string[] = new Array<string>();

@Type(() => ScriptObjectSet)
objectSets: ScriptObjectSet[] = new Array<ScriptObjectSet>();

Expand Down Expand Up @@ -117,6 +119,7 @@ export default class Script implements IAppScript, ISfdmuRunScript {
runInfo: ICommandRunInfo;
canModify: string;


// Additional sobject descriptions for sobject which were nbot included into the export.json
// but necessary for the job
extraSObjectDescriptions: Map<string, SObjectDescribe> = new Map<string, SObjectDescribe>();
Expand Down Expand Up @@ -265,8 +268,11 @@ export default class Script implements IAppScript, ISfdmuRunScript {
let rule = object.operation != OPERATION.Readonly
&& CONSTANTS.NOT_SUPPORTED_OBJECTS.indexOf(object.name) < 0
&& isSupportedForOperation;
let included = !object.excluded && (object.operation == OPERATION.Readonly || rule);
let included = !object.excluded && (object.operation == OPERATION.Readonly || rule) && this.excludedObjects.indexOf(object.name) < 0;
if (!included) {
if (this.excludedObjects.indexOf(object.name) < 0) {
this.excludedObjects.push(object.name);
}
this.logger.infoVerbose(RESOURCES.objectWillBeExcluded, object.name);
}
return included;
Expand Down
19 changes: 14 additions & 5 deletions src/modules/models/script_models/scriptObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,12 @@ export default class ScriptObject implements ISfdmuRunScriptObject {
// ----------------------- Private members -------------------------------------------
private _addOrRemoveFields(describe: SObjectDescribe) {

let fieldDescribes = [...describe.fieldsMap.values()];

// Add multiselect fields
if (this.multiselectPattern) {
let pattern = this.multiselectPattern;
[...describe.fieldsMap.values()].forEach(fieldDescribe => {
fieldDescribes.forEach(fieldDescribe => {

// *** Rules when to add this field to the query:
if (
Expand Down Expand Up @@ -732,8 +734,8 @@ export default class ScriptObject implements ISfdmuRunScriptObject {
});

// Filter excluded fields
this.parsedQuery.fields = this.parsedQuery.fields.filter((f: FieldType) => {
let field = f as SOQLField;
this.parsedQuery.fields = this.parsedQuery.fields.filter((fieldType: FieldType) => {
let field = fieldType as SOQLField;
return this.excludedFields.indexOf(field.field) < 0
});

Expand All @@ -747,8 +749,8 @@ export default class ScriptObject implements ISfdmuRunScriptObject {
// Verify external id value when the original one was not supplied with the script
if (this.originalExternalIdIsEmpty
&& !describe.fieldsMap.get(this.externalId)) {
this.parsedQuery.fields = this.parsedQuery.fields.filter((f: FieldType) => {
let field = f as SOQLField;
this.parsedQuery.fields = this.parsedQuery.fields.filter((fieldType: FieldType) => {
let field = fieldType as SOQLField;
return field.field != this.externalId
});
this.externalId = this.defaultExternalId;
Expand All @@ -763,6 +765,13 @@ export default class ScriptObject implements ISfdmuRunScriptObject {
return isComplexField || !isComplexField && describedFields.indexOf(field.field.toLowerCase()) >= 0;
});

// Filter lookup fields referenced to excluded objects
this.parsedQuery.fields = this.parsedQuery.fields.filter((fieldType: FieldType) => {
let field = fieldType as SOQLField;
let fieldDescribe = fieldDescribes.find(describe => describe.name.toLowerCase() == field.field.toLowerCase() && describe.lookup);
return !fieldDescribe || !this.script.excludedObjects.some(object => object == fieldDescribe.referencedObjectType);
});

// Make each field appear only once
this.parsedQuery.fields = Common.distinctArray(this.parsedQuery.fields, "field");

Expand Down

0 comments on commit aa61b68

Please sign in to comment.