Get total count of records from static query in x++:
Query query = new Query();
//query = contract.parmOurCustomQuery();
QueryRun queryRun = new QueryRun(q);
int totals = 0;
/// get total record count with single datasource
totals = SysQuery::countTotal(queryRun);
/// get total records count with multiple datasources
totals = SysQuery::countLoops();
// get total records count with multiple datasources and adding group by or order by in query with multiple data sources
totals = QueryRun::getQueryRowCount(query,maxInt());