0

I have a @InvocableMethod that is used from Flow builder to create a record.

Also I have a inner class with @invocableVariable.

It is working fine, but I want to use the same method from another class to create records passing a list of Case. How can I convert it?

public class XPTO{
   @InvocableMethod(label='Create record')
   public static List<Id> createRecord(List<Inner> inner){
       for(Inner case : inner){
          //create case...
       }
   }

   public class Inner{
      @InvocableVariable(label='Name')
      public String Name;
   }
}

//Another method calling the createRecord
XPTO.createRecord(listOfCaseToCreate); // Method does not exist or incorrect signature: void createRecord(List<Case>) from the type XPTO

1 Answer 1

1

You just need to overload the method signature. Constructing instances of your inner class should be straightforward, after which you just need to set what attributes you need. If there are more than one, it may be worth adding a constructor of Inner that accepts Case.

public static List<Id> createRecord(List<Case> records)
{
    List<Inner> wrappers = new List<Inner>();
    for (Case record : records)
        wrappers.add(new Inner(record));
    return createRecord(wrappers);
}

public class Inner
{
    @InvocableVariable(label='Name')
    public String name;
    
    public Inner() { }
    public Inner(Case record)
    {
        name = record.Name;
    }
}
3
  • Hi Adrian, Thank you for your help, but I still have the problem. Method does not exist or incorrect signature: void createRecord(List<XPTO.Innerx>) from the type XPTO.
    – M.ho
    Oct 7, 2021 at 16:35
  • Did you remove the existing method signature? Because you shouldn't touch that.
    – Adrian Larson
    Oct 7, 2021 at 17:00
  • Perfect! Thanks!!!
    – M.ho
    Oct 7, 2021 at 19:56

You must log in to answer this question.

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