From cd9220f58165d14383e2a4e57e6de09e5a87c846 Mon Sep 17 00:00:00 2001 From: Justin Wills Date: Fri, 21 Jun 2024 19:54:24 -0300 Subject: [PATCH] added support to use order by in SOQL queries for file addon --- .../components/sfdmu-run/sfdmuRunAddonRuntime.ts | 5 +++-- src/addons/modules/sfdmu-run/ExportFiles/index.ts | 7 ++++++- src/modules/components/common_components/common.ts | 14 +++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts b/src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts index bb92ce0c1..4b23b931b 100644 --- a/src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts +++ b/src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts @@ -119,10 +119,11 @@ export default class SfdmuRunAddonRuntime extends AddonRuntime implements ISfdmu * @param {string} [fieldName="Id"] The field of the IN clause * @param {string} sObjectName The object api name to select * @param {string[]} valuesIN The array of values to use in the IN clause + * @param {string} orderBy Order returned records by a field * @returns {string[]} The array of SOQLs depend on the given values to include all of them */ - createFieldInQueries(selectFields: string[], fieldName: string = "Id", sObjectName: string, valuesIN: string[], whereClause?: string): string[] { - return Common.createFieldInQueries(selectFields, fieldName, sObjectName, valuesIN, whereClause); + createFieldInQueries(selectFields: string[], fieldName: string = "Id", sObjectName: string, valuesIN: string[], whereClause?: string, orderBy?: string): string[] { + return Common.createFieldInQueries(selectFields, fieldName, sObjectName, valuesIN, whereClause, orderBy); } diff --git a/src/addons/modules/sfdmu-run/ExportFiles/index.ts b/src/addons/modules/sfdmu-run/ExportFiles/index.ts index 655455db1..9d717fe64 100644 --- a/src/addons/modules/sfdmu-run/ExportFiles/index.ts +++ b/src/addons/modules/sfdmu-run/ExportFiles/index.ts @@ -40,6 +40,11 @@ interface IOnExecuteArguments { */ targetWhere: string; + /** + * Order how the content document links are populated. + * ORDER BY [contentDocumentLinkOrderBy]. + */ + contentDocumentLinkOrderBy: string; /** * For optimized porocessing, files are grouped into multiple chunks and uploaded sequentially. @@ -297,7 +302,7 @@ export default class ExportFiles extends SfdmuRunAddonModule { ['Id', 'LinkedEntityId', 'ContentDocumentId', 'ShareType', 'Visibility'], 'LinkedEntityId', 'ContentDocumentLink', - [...task.sourceTaskData.idRecordsMap.keys()]); + [...task.sourceTaskData.idRecordsMap.keys()], '', args.contentDocumentLinkOrderBy); let contentDocLinks = await _self.runtime.queryMultiAsync(true, queries); sourceFiles.recIdToDocLinks = Common.arrayToMapMulti(contentDocLinks, ['LinkedEntityId']); diff --git a/src/modules/components/common_components/common.ts b/src/modules/components/common_components/common.ts index 0fef3994e..51d5215d8 100644 --- a/src/modules/components/common_components/common.ts +++ b/src/modules/components/common_components/common.ts @@ -1190,6 +1190,7 @@ export class Common { * @param {string} [fieldName="Id"] The field name to use in the WHERE Field IN (Values) clause * @param {Array} valuesIN Values to use in in the WHERE Field IN (Values) clause * @param {string} whereClause The additional where clause to add besides the IN, like (Id Name ('Name1', 'Name2)) AND (Field__c = 'value') + * @param {string} orderByClause Specify how records are ordered i.e. ORDER By CreatedDate * @returns {Array} Returns an array of SOQLs * @memberof SfdxUtils */ @@ -1198,7 +1199,8 @@ export class Common { fieldName: string = "Id", sObjectName: string, valuesIN: Array, - whereClause?: string): Array { + whereClause?: string, + orderByClause?: string): Array { if (valuesIN.length == 0) { return new Array(); @@ -1220,6 +1222,11 @@ export class Common { //parsedWhere.where.left.closeParen = 1; } + let parsedOrderBy: Query; + if(orderByClause){ + parsedOrderBy = orderByClause && parseQuery('SELECT Id FROM Account ORDER BY ' + orderByClause + '') + } + function* queryGen() { while (true) { @@ -1246,6 +1253,11 @@ export class Common { tempQuery.where.right = parsedWhere.where; tempQuery.where.operator = "AND"; } + + if(parsedOrderBy){ + tempQuery.orderBy = parsedOrderBy.orderBy + } + yield composeQuery(tempQuery); whereValues = new Array();