[SalesForce] Can’t I return a wrapper class for invocable method

I'm writing an Apex Invocable method that should return a wrapper class data and my code is as below.

@InvocableMethod
    global static List<List<prodWrap>> getProducts() 
    {
        List<List<prodWrap>> wrapper = new List<List<prodWrap>>();
         List<Product2> productsAvailable = [SELECT Id, Name FROM Product2 WHERE Name LIKE '%Hoses%'];
        List<prodWrap> responseList=new List<prodWrap>();
        for (Product2 products: productsAvailable ){       
            PricebookEntry pe=[SELECT Id, Pricebook2Id, Product2.Name, UnitPrice FROM PricebookEntry where Product2Id=:products.Id order by createddate desc LIMIT 1];
            responseList.add(new prodWrap(products.Name, Integer.valueOf(pe.UnitPrice)));
        }
        wrapper.add(responseList);
        return wrapper;
    }
    
    public class prodWrap {
        public String name {get; set;}
        public Integer price {get; set;}
        public prodWrap(String name, Integer price){
            this.name = name;
            this.price = price;
        }
    }

the error that I get is InvocableMethod methods do not support return type of List<List<ClassName.prodWrap>>. Please let me know where am I going wrong and how can I fix this.

Thanks

Best Answer

As per the documentation, you can return:

A list of a user-defined type, containing variables of the supported types above or user-defined Apex types, with the InvocableVariable annotation. Create a custom global or public Apex class to implement your data type, and make sure that your class contains at least one member variable with the invocable variable annotation.

If adding the annotations to the ProdWrap properties doesn't resolve, you may find you need to use a top level class, or you might need to structure the wrapper to contain the nested list.