Reputation: 1183
I am receiving data from an external api in apex class. I am using a wrapper class to pass this data to salesforce screen flow. In debug the flow is showing that it receives data from the apex class. How can I convert this data to a collection variable to show in flow data table. In data table I tried to create new resource and tried to assign Apex defined variable but whenever I checked Multiple Values the data table just rejects it and no resource is shown in the resource. This is the data I am trying to show in data table.
{
"Product_Catagories": [{
"id": "8ad08aef8534de220185400383d82def",
"name": "Product One",
"description": "Desc One",
"region": "",
"category": "Main Products",
"ProductFamily": "Main",
"RelatedProducts": "POC-B0000001",
"productfeatures": []
}, {
"id": "8ad0887e8534de2701853fff5a9b22ee",
"name": "Product Two",
"description": "Desc Two",
"region": "",
"category": "Main Products",
"ProductFamily": "Main",
"RelatedProducts": "POC-B0000002",
"productfeatures": []
}, {
"id": "8ad08aef8534de2201853ffe48fc08f6",
"name": "Product Three",
"description": "Desc Three",
"region": "",
"category": "Main Products",
"ProductFamily": "Main",
"RelatedProducts": "POC-B0000003",
"productfeatures": []
}]
}
Upvotes: 0
Views: 2156
Reputation: 19622
Show some code, not just the message you got.
You're using https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm right?
3rd example on that page shows how to return a list of helper class objects, public static List <Results> execute
. So what you need is something like
public static List<CategoryWrapper> execute(List<Id> ids){
String response = new Http().send(yourRequestBuilder(ids)).getBody();
if(String.isNotBlank(response)){
Wrapper w = (Wrapper) JSON.deserialize(response, Wrapper.class); // your "main" helper class
if(w.Product_Catagories != null){
return w.ProductCatagories; // return to flow the array inside, not the whole object
}
}
return null; // something went wrong, or maybe throw exception
}
There may even be a code-free way to do it, we don't know what your API is. https://help.salesforce.com/s/articleView?id=sf.flow_http_callout.htm&type=5
Upvotes: 0