Skip to content

Commit

Permalink
Merge pull request #803 from jawills/order-by-file-addon
Browse files Browse the repository at this point in the history
feat: Added support to use order by in SOQL queries for the core:ExportFiles Add On
  • Loading branch information
hknokh authored Aug 13, 2024
2 parents 6858bb5 + cd9220f commit b0945c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
7 changes: 6 additions & 1 deletion src/addons/modules/sfdmu-run/ExportFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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']);
Expand Down
14 changes: 13 additions & 1 deletion src/modules/components/common_components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ export class Common {
* @param {string} [fieldName="Id"] The field name to use in the WHERE Field IN (Values) clause
* @param {Array<string>} 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<string>} Returns an array of SOQLs
* @memberof SfdxUtils
*/
Expand All @@ -1199,7 +1200,8 @@ export class Common {
fieldName: string = "Id",
sObjectName: string,
valuesIN: Array<string>,
whereClause?: string): Array<string> {
whereClause?: string,
orderByClause?: string): Array<string> {

if (valuesIN.length == 0) {
return new Array<string>();
Expand All @@ -1221,6 +1223,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) {
Expand All @@ -1247,6 +1254,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<string>();
Expand Down

0 comments on commit b0945c2

Please sign in to comment.