Search code examples
salesforcewrapperapex-codesalesforce-flow

How to Access Nested Wrapper Class in Flow Apex Action?


I'm working on an Apex Invocable Method that returns a wrapper class with nested wrapper objects. However, in Flow, I'm unable to access the inner wrapper fields properly.

Here’s a simplified version of my Apex class:

public class RecordCompletenessAction {

public class FlowOutputWrapper { 

    @InvocableVariable 

    public ParentWrapper parent; 



    @InvocableVariable 

    public Integer overallWeightage; 

} 



public class ParentWrapper { 

    @InvocableVariable 

    public MyWrapper field1; 

    @InvocableVariable 

    public MyWrapper field2; 

} 



public class MyWrapper { 

    @InvocableVariable 

    public String fieldName; 

    @InvocableVariable 

    public Boolean display; 

} 



@InvocableMethod 

public static List<FlowOutputWrapper> processFlowAction(List<Id> recordIds) { 

    List<FlowOutputWrapper> results = new List<FlowOutputWrapper>(); 



    ParentWrapper parent = new ParentWrapper(); 

    parent.field1 = new MyWrapper(); 

    parent.field1.fieldName = 'Example Field'; 

    parent.field1.display = true; 



    FlowOutputWrapper output = new FlowOutputWrapper(); 

    output.parent = parent; 

    output.overallWeightage = 80; 



    results.add(output); 

    return results; 

} 

}

🔹 Issue:

In

Flow

, when I try to access {!Process_Data.parent.field1.fieldName}, I get an error:

enter image description here

🔹 What I’ve Tried:

Marking variables with @InvocableVariable – No luck. Using different data structures (List, Map, Direct Assignment) – Flow still doesn't recognize the inner fields. 🔹 Question:

How can I properly structure my nested wrapper classes so that Flow recognizes and allows access to the inner fields (field1.fieldName)? Are there any limitations in Flow regarding nested objects inside Apex Invocable Actions? Any insights or workarounds would be appreciated! 🚀


Solution

  • They need to be top-level classes, in their own files. You can't reach into inner and can't use them as "Apex-Defined" flow variable type.

    See these answers on SF-dedicated site https://salesforce.stackexchange.com/a/370750/799, https://salesforce.stackexchange.com/a/388353/799

    and https://help.salesforce.com/s/articleView?id=platform.flow_considerations_apex_data_type.htm&type=5

    Apex: (...) Inner classes aren’t supported.