Skip to content

Commit b0945c2

Browse files
authored
Merge pull request #803 from jawills/order-by-file-addon
feat: Added support to use order by in SOQL queries for the core:ExportFiles Add On
2 parents 6858bb5 + cd9220f commit b0945c2

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/addons/components/sfdmu-run/sfdmuRunAddonRuntime.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ export default class SfdmuRunAddonRuntime extends AddonRuntime implements ISfdmu
119119
* @param {string} [fieldName="Id"] The field of the IN clause
120120
* @param {string} sObjectName The object api name to select
121121
* @param {string[]} valuesIN The array of values to use in the IN clause
122+
* @param {string} orderBy Order returned records by a field
122123
* @returns {string[]} The array of SOQLs depend on the given values to include all of them
123124
*/
124-
createFieldInQueries(selectFields: string[], fieldName: string = "Id", sObjectName: string, valuesIN: string[], whereClause?: string): string[] {
125-
return Common.createFieldInQueries(selectFields, fieldName, sObjectName, valuesIN, whereClause);
125+
createFieldInQueries(selectFields: string[], fieldName: string = "Id", sObjectName: string, valuesIN: string[], whereClause?: string, orderBy?: string): string[] {
126+
return Common.createFieldInQueries(selectFields, fieldName, sObjectName, valuesIN, whereClause, orderBy);
126127
}
127128

128129

src/addons/modules/sfdmu-run/ExportFiles/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ interface IOnExecuteArguments {
4040
*/
4141
targetWhere: string;
4242

43+
/**
44+
* Order how the content document links are populated.
45+
* ORDER BY [contentDocumentLinkOrderBy].
46+
*/
47+
contentDocumentLinkOrderBy: string;
4348

4449
/**
4550
* For optimized porocessing, files are grouped into multiple chunks and uploaded sequentially.
@@ -297,7 +302,7 @@ export default class ExportFiles extends SfdmuRunAddonModule {
297302
['Id', 'LinkedEntityId', 'ContentDocumentId', 'ShareType', 'Visibility'],
298303
'LinkedEntityId',
299304
'ContentDocumentLink',
300-
[...task.sourceTaskData.idRecordsMap.keys()]);
305+
[...task.sourceTaskData.idRecordsMap.keys()], '', args.contentDocumentLinkOrderBy);
301306

302307
let contentDocLinks = await _self.runtime.queryMultiAsync(true, queries);
303308
sourceFiles.recIdToDocLinks = Common.arrayToMapMulti(contentDocLinks, ['LinkedEntityId']);

src/modules/components/common_components/common.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ export class Common {
11911191
* @param {string} [fieldName="Id"] The field name to use in the WHERE Field IN (Values) clause
11921192
* @param {Array<string>} valuesIN Values to use in in the WHERE Field IN (Values) clause
11931193
* @param {string} whereClause The additional where clause to add besides the IN, like (Id Name ('Name1', 'Name2)) AND (Field__c = 'value')
1194+
* @param {string} orderByClause Specify how records are ordered i.e. ORDER By CreatedDate
11941195
* @returns {Array<string>} Returns an array of SOQLs
11951196
* @memberof SfdxUtils
11961197
*/
@@ -1199,7 +1200,8 @@ export class Common {
11991200
fieldName: string = "Id",
12001201
sObjectName: string,
12011202
valuesIN: Array<string>,
1202-
whereClause?: string): Array<string> {
1203+
whereClause?: string,
1204+
orderByClause?: string): Array<string> {
12031205

12041206
if (valuesIN.length == 0) {
12051207
return new Array<string>();
@@ -1221,6 +1223,11 @@ export class Common {
12211223
//parsedWhere.where.left.closeParen = 1;
12221224
}
12231225

1226+
let parsedOrderBy: Query;
1227+
if(orderByClause){
1228+
parsedOrderBy = orderByClause && parseQuery('SELECT Id FROM Account ORDER BY ' + orderByClause + '')
1229+
}
1230+
12241231

12251232
function* queryGen() {
12261233
while (true) {
@@ -1247,6 +1254,11 @@ export class Common {
12471254
tempQuery.where.right = parsedWhere.where;
12481255
tempQuery.where.operator = "AND";
12491256
}
1257+
1258+
if(parsedOrderBy){
1259+
tempQuery.orderBy = parsedOrderBy.orderBy
1260+
}
1261+
12501262
yield composeQuery(tempQuery);
12511263

12521264
whereValues = new Array<string>();

0 commit comments

Comments
 (0)