Hi,
I want to pass a list of string to a method which returns a list of wrapper class.
This is an example code:
But I'm not albe to see the list in the variable to get it as an output and loop through it in the flow.
Has anyone a solution for this please?
thanks!
global class StringProcessor { // Define the wrapper class global class WrapperClass { @InvocableVariable global String name; @InvocableVariable global Integer accountNumber; @InvocableVariable global String code; // Constructor public WrapperClass(String name, Integer accountNumber, String code) { this.name = name; this.accountNumber = accountNumber; this.code = code; } } // Method to process the list of strings @InvocableMethod global static list<List<WrapperClass>> processStrings(List<String> inputStrings) { List<WrapperClass> result = new List<WrapperClass>(); for (String str : inputStrings) { // Example processing: split the string by commas List<String> parts = str.split(','); if (parts.size() == 3) { String name = parts[0]; Integer accountNumber = Integer.valueOf(parts[1]); String code = parts[2]; // Create a new instance of the wrapper class and add it to the result list result.add(new WrapperClass(name, accountNumber, code)); } } list<List<WrapperClass>> endResult; endResult.add(result); return endResult; }}
#Salesforce Developer
2 risposte
Sounds like the flow isn't recognizing the wrapper class properly. Have you tried making the wrapper class serializable or using a collection variable in the flow? That might help it process the list correctly.