I'm looking to provide a Flow User with a list of Search Results based on a query. I have the following set of code, and haven't been able to figure out how to get it to work. (I've tried moving the classes to their own files, adding them to a Permission Set assigned to the running user).
Once the code below is in an org, I can create a flow that calls the action (say passing an argument of Banana). I can then make a Loop element that loops over results
.
My error occurs when I try to reference anything within the Fruit
class. I get the error: The "name" field doesn't exist on the "ComplexAction$Fruit" object, or you don't have access to the field.
Any tips on making this work? I have seen this SO post, though my error happens after the screens in the post. How to iterate over List<List<String>> which is returned by Apex, in a flow?
global with sharing class ComplexAction {
global class Basket { // this is our group of search results
@InvocableVariable(label='Original Query')
global String origQuery;
@InvocableVariable(label='Results')
global List<Fruit> results;
}
global class Fruit {
@InvocableVariable(label='Fruit Name')
global String name;
}
@InvocableMethod(label='Search for Fruit')
global static List<Basket> searchForFruit(List<String> criteria) {
//imagine code that does something useful
return null; //this doesn't matter for the purpose of this post
}
}
Fruit
class" (i.e., where are you getting the error)? In a Flow? Inside yoursearchForFruit()
method? 2) For clarification, is it a copying/pasting to SFSE error, or does your error stateComplexActions
? Notice that has ans
but your class name does not, so I'm not sure how you are referencing it. It seems to me that some additional code and/or Flow details need to be shared.ComplexActions$Fruit
is indeed a typo, I'll fix that in the post. I am getting my error in the flow, when I try to use the results. So in the flow, i have: - Action - Iterate Loop (looping through Action'sresults
variable - Try to use Loop Var (which is a single result, ofFruit
class). This is where I get the error where the Fruit variable name doesn't exist