I am super close to getting this process to work, however, I am a little unclear as to how to deal with the @invocableVariable portion of the process. And just to preface... I am NOT a coder, like at all, so this has been a labor for me.
When I run debug in my flow, it all runs through properly and creates the proper number of records when I change 'LIMIT :NumberOfRecords' to a literal number, like '3'. But I would like to pass a value to the class in an @InvocableVariable titled NumberOfRecords and have it use it in the query.
I have looked at a million examples, but just can't seem to put it to practice.
Any direction would be GREATLY appreciated! Please see my example code below:
public class InvocableAuditDraft {
@InvocableMethod(label='Select Accounts for Audit'
description='Returns a list of accounts eligible for an Audit.'
category='Account')
public static List<List<Account>> getAccountIds(List<ID> ids) {
List<List<Account>> accountList = new List<List<Account>>();
List<Account> accountIds = [SELECT Id FROM Account where Status__c = 'Open' LIMIT 5000];
Integer count = accountIds.size();
Integer rand = Math.floor(Math.random() * count).intValue();
List<Account> accounts = [SELECT Id FROM Account WHERE Id in :accountIds LIMIT :NumberOfRecords OFFSET :rand];
accountList.add(accounts);
return accountList;
}
public class FlowInputs {
@InvocableVariable(required=true)
public String NumberOfRecords;
}
}