-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1500 from JeroenSfdc/patch-8
Update QueryWithLimit.cls
- Loading branch information
Showing
1 changed file
with
19 additions
and
21 deletions.
There are no files selected for viewing
40 changes: 19 additions & 21 deletions
40
..._action_components/CollectionProcessors/force-app/main/default/classes/QueryWithLimit.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,43 @@ | ||
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<QueryResults> 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<QueryResults> getNrecords(QueryParameters[] queryParams){ | ||
|
||
if (queryParams[0].numberOfRecords >= 50000) { | ||
throw new FlowApexActionException('You cannot query more than 50000 records.'); | ||
} | ||
|
||
list<QueryResults> result = new list<QueryResults>(); | ||
string query = 'Select '+ queryParams[0].fieldsToQuery + ' FROM ' + queryParams[0].objectApiName + ' LIMIT ' + queryParams[0].numberOfRecords; | ||
try{ | ||
sObject[] recordList = database.query(query); | ||
//system.debug(recordList); | ||
List<QueryResults> result = new List<QueryResults>(); | ||
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; | ||
} | ||
|
||
/* 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; | ||
} | ||
|
||
} | ||
} |