1

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": []
    }]
}
2
  • I mean... it's not wrong? That's not an array. That's an object with 1 field Product_Catagories which happens to contain an array. Have you tried passing that to flow rather than whole thing? Commented Jan 18, 2023 at 19:00
  • I am new to flows. Please explain how we can pass this to the flow. Commented Jan 19, 2023 at 4:37

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.