Skip to content

Commit

Permalink
Merge pull request #61 from forcedotcom/SmallFeatures
Browse files Browse the repository at this point in the history
#60 Added support for polymorphic lookup fields
  • Loading branch information
hknokh authored May 30, 2020
2 parents dcfea9d + 385875d commit 58929da
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

```bash
### ------------------------------------------------------------------------------- ###
### ------ Latest stable version: 2.8.342 ------------------------------------------ ###
### ------ Latest stable version: 2.8.4 ------------------------------------------- ###
### ------ !! Highly recommended always keeping your local copy up-to-date !! ----- ###
### -------!! All older versions may not functioning properly !! ------------------ ###
### ------------------------------------------------------------------------------- ###

### Applied mandatory patch starting from the version 2.8.330
### (All earlier versions < 2.8.330 are outdated and may not functioning properly)
```
#### For the detailed documentation visit the project WIKI: [https://github.com/forcedotcom/SFDX-Data-Move-Utility/wiki](https://github.com/forcedotcom/SFDX-Data-Move-Utility/wiki)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sfdmu",
"description": "The advanced Salesforce Data Loader SFDX Plugin (SFDMU) will assist you to populate your org (scratch/development/sandbox/production) with data imported from another org or CSV files. Supports Delete, Insert, Update and Upsert for multiple related sObjects.",
"version": "2.8.342",
"version": "2.8.4",
"author": "hknokh@salesforce.com",
"bugs": "https://github.com/forcedotcom/SFDX-Data-Move-Utility/issues",
"dependencies": {
Expand Down
23 changes: 13 additions & 10 deletions src/modules/components/common_components/sfdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'soql-parser-js';
import { CONSTANTS } from './statics';
import { DescribeSObjectResult, QueryResult } from 'jsforce';
import { SFieldDescribe, SObjectDescribe, ScriptOrg } from '../../models';
import { SFieldDescribe, SObjectDescribe, ScriptOrg, CommandExecutionError } from '../../models';
import { Common } from './common';
import { IOrgConnectionData } from '../../models/common_models/helper_interfaces';

Expand Down Expand Up @@ -95,17 +95,20 @@ export class Sfdx {
useBulkQueryApi: boolean = false,
csvFullFilename?: string,
sFieldsDescribeMap?: Map<string, SFieldDescribe>): Promise<Array<any>> {

let self = this;
if (csvFullFilename && sFieldsDescribeMap) {
return await ___readAndFormatCsvRecordsAsync();
}
let records = [].concat(await ___queryAsync(soql));
if (soql.indexOf("FROM Group") >= 0) {
soql = soql.replace("FROM Group", "FROM User");
records = records.concat(await ___queryAsync(soql));
try {
if (csvFullFilename && sFieldsDescribeMap) {
return await ___readAndFormatCsvRecordsAsync();
}
let records = [].concat(await ___queryAsync(soql));
if (soql.indexOf("FROM Group") >= 0) {
soql = soql.replace("FROM Group", "FROM User");
records = records.concat(await ___queryAsync(soql));
}
return records;
} catch (ex) {
throw new CommandExecutionError(ex.message);
}
return records;

// ------------------ internal functions ------------------------- //
async function ___queryAsync(soql: string): Promise<Array<any>> {
Expand Down
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 @@ -23,6 +23,7 @@ export const CONSTANTS = {
COMPLEX_FIELDS_QUERY_SEPARATOR: '$',
COMPLEX_FIELDS_QUERY_PREFIX: '$$',
COMPLEX_FIELDS_SEPARATOR: ';',
REFERENCE_FIELD_OBJECT_SEPARATOR: '$',

SCRIPT_FILE_NAME: 'export.json',
CSV_SOURCE_SUB_DIRECTORY: "source",
Expand Down
28 changes: 22 additions & 6 deletions src/modules/models/script_models/scriptObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default class ScriptObject {
processAllSource: boolean = false;
processAllTarget: boolean = false;
multiselectPattern: any;
referenceFieldToObjectMap: Map<string, string> = new Map<string, string>();

get task(): MigrationJobTask {
return this.script.job.getTaskBySObjectName(this.name);
Expand Down Expand Up @@ -325,14 +326,14 @@ export default class ScriptObject {
try {
// Retrieve sobject metadata
this.sourceSObjectDescribe = await apisf.describeSObjectAsync(this.name);
[...this.sourceSObjectDescribe.fieldsMap.values()].forEach(x => x.scriptObject = this);
this._updateSObjectDescribe(this.sourceSObjectDescribe);

if (this.script.targetOrg.media == DATA_MEDIA_TYPE.File) {
this.targetSObjectDescribe = this.sourceSObjectDescribe;
}

// Add fields by the multiselect keywords + filter query
this._addOrRemmoveFields(this.sourceSObjectDescribe);
this._addOrRemoveFields(this.sourceSObjectDescribe);

// Check fields existance
this._validateFields(this.sourceSObjectDescribe, true);
Expand All @@ -354,13 +355,13 @@ export default class ScriptObject {
try {
// Retrieve sobject metadata
this.targetSObjectDescribe = await apisf.describeSObjectAsync(this.name);
[...this.targetSObjectDescribe.fieldsMap.values()].forEach(x => x.scriptObject = this);
this._updateSObjectDescribe(this.targetSObjectDescribe);

if (this.script.sourceOrg.media == DATA_MEDIA_TYPE.File) {
this.sourceSObjectDescribe = this.targetSObjectDescribe;

// Add fields by the multiselect keywords + filter query
this._addOrRemmoveFields(this.targetSObjectDescribe);
this._addOrRemoveFields(this.targetSObjectDescribe);
}

// Check fields existance
Expand Down Expand Up @@ -407,7 +408,7 @@ export default class ScriptObject {
}

// ----------------------- Private members -------------------------------------------
private _addOrRemmoveFields(describe: SObjectDescribe) {
private _addOrRemoveFields(describe: SObjectDescribe) {
if (this.multiselectPattern) {
let fieldsInOriginalQuery = [].concat(this.fieldsInQuery);
let pattern = this.multiselectPattern;
Expand Down Expand Up @@ -435,6 +436,15 @@ export default class ScriptObject {
}
}

private _updateSObjectDescribe(describe: SObjectDescribe) {
[...this.sourceSObjectDescribe.fieldsMap.values()].forEach(x => {
x.scriptObject = this;
if (x.lookup && this.referenceFieldToObjectMap.has(x.name)){
x.referencedObjectType = this.referenceFieldToObjectMap.get(x.name);
}
});
}

private _validateFields(describe: SObjectDescribe, isSource: boolean) {

if (this.fieldsInQuery.length == 0) {
Expand Down Expand Up @@ -478,7 +488,13 @@ export default class ScriptObject {
} else if (CONSTANTS.MULTISELECT_SOQL_KEYWORDS.indexOf(fieldName) >= 0) {
___set(fieldName);
} else if (fieldName != "id") {
parsedQuery.fields.push(getComposedField((<SOQLField>field).field));
fieldName = (<SOQLField>field).field;
let parts = fieldName.split(CONSTANTS.REFERENCE_FIELD_OBJECT_SEPARATOR);
if (parts.length > 1) {
self.referenceFieldToObjectMap.set(parts[0], parts[1]);
fieldName = parts[0];
}
parsedQuery.fields.push(getComposedField(fieldName));
}
});
this.query = composeQuery(parsedQuery);
Expand Down

0 comments on commit 58929da

Please sign in to comment.