Skip to main content
Added backticks around list types outside of code block, removed extraneous whitespace from code block.
Source Link
Derek F
  • 64.1k
  • 15
  • 55
  • 104

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List>List<List<CustomSobject>> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a ListList<CustomSobject> the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error.

@InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){
    

    //created to hold return list of lists
    List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();
 
    //The data set to be returned
    List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];
    
    for (Create_Product__c products: productsAvailable ){
 
        List<Create_Product__c> responseList = new List<Create_Product__c>();

        responseList[0].Product_Code__c = products.Product_Code__c;
        responseList[0].Starting_Price__c = products.Starting_Price__c;

        wrapper.add(responseList);
        
        }

 
    
    return wrapper;
 
}

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a List the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error.

@InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){
    

    //created to hold return list of lists
    List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();
 
    //The data set to be returned
    List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];
    
    for (Create_Product__c products: productsAvailable ){
 
    List<Create_Product__c> responseList = new List<Create_Product__c>();

        responseList[0].Product_Code__c = products.Product_Code__c;
        responseList[0].Starting_Price__c = products.Starting_Price__c;

        wrapper.add(responseList);
        
        }

 
    
    return wrapper;
 
}

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List<CustomSobject>> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a List<CustomSobject> the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error.

@InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){
    //created to hold return list of lists
    List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();
 
    //The data set to be returned
    List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];
    
    for (Create_Product__c products: productsAvailable ){
        List<Create_Product__c> responseList = new List<Create_Product__c>();

        responseList[0].Product_Code__c = products.Product_Code__c;
        responseList[0].Starting_Price__c = products.Starting_Price__c;

        wrapper.add(responseList);
    }

    return wrapper;
}
added 65 characters in body; edited tags
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a List the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error. Any suggestions appreciated.

 @InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){
    

    //created to hold return list of lists
    List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();
 
    //The data set to be returned
    List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];
    
    for (Create_Product__c products: productsAvailable ){

    List<Create_Product__c> responseList = new List<Create_Product__c>();

        responseList[0].Product_Code__c = products.Product_Code__c;
        responseList[0].Starting_Price__c = products.Starting_Price__c;

        wrapper.add(responseList);
        
        }


    
    return wrapper;

}

}

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a List the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error. Any suggestions appreciated.

 @InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){


//created to hold return list of lists
List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();

//The data set to be returned
List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];

for (Create_Product__c products: productsAvailable ){

List<Create_Product__c> responseList = new List<Create_Product__c>();

    responseList[0].Product_Code__c = products.Product_Code__c;
    responseList[0].Starting_Price__c = products.Starting_Price__c;

    wrapper.add(responseList);
    
    }



return wrapper;

}

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a List the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error.

@InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){
    

    //created to hold return list of lists
    List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();
 
    //The data set to be returned
    List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];
    
    for (Create_Product__c products: productsAvailable ){

    List<Create_Product__c> responseList = new List<Create_Product__c>();

        responseList[0].Product_Code__c = products.Product_Code__c;
        responseList[0].Starting_Price__c = products.Starting_Price__c;

        wrapper.add(responseList);
        
        }


    
    return wrapper;

}
Source Link
EMC
  • 155
  • 1
  • 8

Invocable Method returning List of List - Attempt to Dereference a null object

I'm working with cloud flow designer and having some issues with the Apex class callout. I know I will need to return a List<List> from the invocable method in order to process the collection. But I am stuck overcomplicating the code in order to get what I would normally use a List for into the right format to return. I probably need an additional for loop...? If I only use a List the Flow will not be able to process it as a collection returning multiple records. Below is my method, this current version compiles but the flow will throw an "Attempt to de-reference a null object" error. Any suggestions appreciated.

 @InvocableMethod(label = 'Services Available')
public static List<List<Create_Product__c>> getServices(List<Address__c> addressInput){


//created to hold return list of lists
List<List<Create_Product__c>> wrapper = new List<List<Create_Product__c>>();

//The data set to be returned
List<Create_Product__c> productsAvailable = [SELECT Product_Code__c, Starting_Price__c FROM Create_Product__c];

for (Create_Product__c products: productsAvailable ){

List<Create_Product__c> responseList = new List<Create_Product__c>();

    responseList[0].Product_Code__c = products.Product_Code__c;
    responseList[0].Starting_Price__c = products.Starting_Price__c;

    wrapper.add(responseList);
    
    }



return wrapper;

}