diff --git a/flow_action_components/CollectionProcessors/force-app/main/default/classes/QueryWithLimit.cls b/flow_action_components/CollectionProcessors/force-app/main/default/classes/QueryWithLimit.cls index 5b4f679b3..794747e39 100755 --- a/flow_action_components/CollectionProcessors/force-app/main/default/classes/QueryWithLimit.cls +++ b/flow_action_components/CollectionProcessors/force-app/main/default/classes/QueryWithLimit.cls @@ -1,24 +1,23 @@ public with sharing class QueryWithLimit { - /* Class definition for throwing custom exceptions */ public class FlowApexActionException extends Exception{} - @InvocableMethod(label='Query N records [USF Collection Processor]' description='Returns a list of N records, where is N specified by a user as a flow input.' category='Util' iconName='resource:CollectionProcessorsSVG:colproc') - public static list getNrecords(QueryParameters[] queryParams){ - - if(queryParams[0].numberOfRecords >= 50000) + @InvocableMethod(Label='Query N records [USF Collection Processor]' Description='Returns a list of N records, where is N specified by a user as a flow input.' Category='Util' IconName='resource:CollectionProcessorsSVG:colproc') + public static List getNrecords(QueryParameters[] queryParams){ + + if (queryParams[0].numberOfRecords >= 50000) { throw new FlowApexActionException('You cannot query more than 50000 records.'); + } - list result = new list(); - string query = 'Select '+ queryParams[0].fieldsToQuery + ' FROM ' + queryParams[0].objectApiName + ' LIMIT ' + queryParams[0].numberOfRecords; - try{ - sObject[] recordList = database.query(query); - //system.debug(recordList); + List result = new List(); + String query = 'SELECT '+ queryParams[0].fieldsToQuery + ' FROM ' + queryParams[0].objectApiName + ' LIMIT ' + queryParams[0].numberOfRecords; + try { + SObject[] recordList = Database.query(query); QueryResults qr = new QueryResults(); qr.records = recordList; result.add(qr); - } catch(Exception e){ + } catch(Exception e) { throw e; } return result; @@ -26,20 +25,19 @@ public with sharing class QueryWithLimit { /* Input parameters for the Apex action */ public class QueryParameters{ - @InvocableVariable(label='Api name of the Object' required = true ) - public string objectApiName; + @InvocableVariable(Label='Api name of the Object' Required = true ) + public String objectApiName; - @InvocableVariable(label='API names of the fields to query(Comma separated)' required = true) - public string fieldsToQuery; + @InvocableVariable(Label='API names of the fields to query(Comma separated)' Required = true) + public String fieldsToQuery; - @InvocableVariable(label='Number of records to query' required = true) - public integer numberOfRecords; + @InvocableVariable(Label='Number of records to query' Required = true) + public Integer numberOfRecords; } /* Output parameters of the Apex action */ public class QueryResults{ - @InvocableVariable(label='List of records') - public sObject[] records; + @InvocableVariable(Label='List of records') + public SObject[] records; } - -} \ No newline at end of file +}