Skip to content

Commit cd9220f

Browse files
committed
added support to use order by in SOQL queries for file addon
1 parent 570227f commit cd9220f

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
@@ -1190,6 +1190,7 @@ export class Common {
11901190
* @param {string} [fieldName="Id"] The field name to use in the WHERE Field IN (Values) clause
11911191
* @param {Array<string>} valuesIN Values to use in in the WHERE Field IN (Values) clause
11921192
* @param {string} whereClause The additional where clause to add besides the IN, like (Id Name ('Name1', 'Name2)) AND (Field__c = 'value')
1193+
* @param {string} orderByClause Specify how records are ordered i.e. ORDER By CreatedDate
11931194
* @returns {Array<string>} Returns an array of SOQLs
11941195
* @memberof SfdxUtils
11951196
*/
@@ -1198,7 +1199,8 @@ export class Common {
11981199
fieldName: string = "Id",
11991200
sObjectName: string,
12001201
valuesIN: Array<string>,
1201-
whereClause?: string): Array<string> {
1202+
whereClause?: string,
1203+
orderByClause?: string): Array<string> {
12021204

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

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

12241231
function* queryGen() {
12251232
while (true) {
@@ -1246,6 +1253,11 @@ export class Common {
12461253
tempQuery.where.right = parsedWhere.where;
12471254
tempQuery.where.operator = "AND";
12481255
}
1256+
1257+
if(parsedOrderBy){
1258+
tempQuery.orderBy = parsedOrderBy.orderBy
1259+
}
1260+
12491261
yield composeQuery(tempQuery);
12501262

12511263
whereValues = new Array<string>();

0 commit comments

Comments
 (0)