jamessimone / apex-async-processor

Abstract away which async framework is being used within Salesforce in favor of dynamically using the most appropriate solution for the problem at hand.
MIT License
34 stars 3 forks source link

Issue encountered with Database.countQuery() and ORDER BY filter #2

Closed Anuja-dadheech20 closed 8 months ago

Anuja-dadheech20 commented 8 months ago

An exception will occur in the AsyncProcessor class at line 94 when retrieving the record count using Database.countQuery if the query includes an "ORDER BY" expression. The exception message will read as follows: "System.UnexpectedException: COUNT() and ORDER BY may not be used together."

Could you please review the code snippet below and share your thoughts on whether this is an effective way to resolve the issue?

String recordCountQuery = query.replace(query.substringBeforeLast(' from '), 'select count() ');
Integer indexOfOrderBy = query.lastIndexOf('order by');
if (indexOfOrderBy != -1) {
    recordCountQuery = recordCountQuery.replace(query.substring(indexOfOrderBy), ' ');
}
jamessimone commented 8 months ago

@Anuja-dadheech20 let me take a look at this today - I will push up a fix for this

jamessimone commented 8 months ago

@Anuja-dadheech20 - this is all set, thanks for pointing this out!