Create callable actions that function across various objects.

Following the Spring 20 update, it is now possible to craft reusable Apex actions employing the generic sObject and List<sObject> data types. Instead of creating a distinct action for each object, you can now construct a singular action capable of functioning across multiple objects.

Developers have the flexibility to design a filter or sort action applicable to any collection of records, spanning from accounts and contacts to custom objects. Previously, the absence of support for generic data types hindered the utilization of polymorphic Apex structures in invocable actions.

To implement this, either generate a custom action or modify an existing one, utilizing the sObject or List<sObject> data type in invocable methods and attributes.

public with sharing class GetFirstFromCollection {  
    public static List <Results> execute (List<Requests> requestList) {

        List<SObject> inputCollection = requestList[0].inputCollection;
        SObject outputMember = inputCollection[0];
        //Create a Results object to hold the return values
        Results response = new Results();

        //Add the return values to the Results object
        response.outputMember = outputMember;

        //Wrap the Results object in a List container 
        //(an extra step added to allow this interface to also support bulkification)
        List<Results> responseWrapper= new List<Results>();
        return responseWrapper;    

    public class Requests {

      public List<SObject> inputCollection;

    public class Results {     

      public SObject outputMember;

In the past, the illustrative class would have been specifically associated with either the Account, Contact, or myCustomObject__c object. However, with the current approach, developers generate a single action, and the Flow Builder administrator can select the desired object each time the action is employed.