1

I'm getting this error when I insert more than one record into an custom object that has a record-triggered Flow. Flow calls an invocable method to do parse multipicklist values. here's my invocable method:

global class GetVehicleType
{
    @InvocableMethod
    public static List<List<String>> getVehicleType(List<myObject__c> myObj) 
    {
        List<List<String>> ListVehicleType = new List<List<String>>();
        List<String> VehicleType = new List<String>();
        for(myObject__c obj : myObj)
        {
            if(obj.VehicleType__c != null)
            {
                VehicleType.addAll(obj.VehicleType__c.split(';'));
            }
        }
        ListVehicleType.add(VehicleType);
       
       return ListVehicleType;
    }
}

Does anyone know what am I doing wrong ? Thanks !

1 Answer 1

1

You're not reinitializing the List<String> for each iteration, which is probably causing the problem:

global class GetVehicleType {
    @InvocableMethod
    public static List<List<String>> getVehicleType(List<myObject__c> myObj) {
        List<List<String>> ListVehicleType = new List<List<String>>();
        for(myObject__c obj : myObj) {
            // Initialize for every loop
            List<String> VehicleType = new List<String>();
            if(obj.VehicleType__c != null) {
                VehicleType.addAll(obj.VehicleType__c.split(';'));
            }
            ListVehicleType.add(VehicleType);
        }
       return ListVehicleType;
    }
}
1
  • it works, thank you May 10, 2022 at 12:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .