I have a record-triggered flow on the Accounts object. This flow invokes an Apex Action method called sayHello, which takes the name of a public group as its argument:

public class MyClass {
    @InvocableMethod(label='Say Hello')
    public static void sayHello(String groupName) {
        List<GroupMember> newList = [SELECT Group.Id 
                                        FROM GroupMember
                                        WHERE Group.Name = groupName];
        HelloSettings__c match = [SELECT Group_Name
                                        FROM HelloSettings__c 
                                        WHERE Group.Name = groupName];

        List<GroupMember> oldList = [SELECT Group.Id
                                        FROM GroupMember
                                        WHERE Group.Name = match.Group_Name__c]
        // compare oldList to newList to see who has left 
        // since the last time `sayHello()` was called
        // store newList in Old_List__c picklist field
        // so that `sayHello()` can access it the next 
        // time it is called
        match.Old_List__c = newList;


sayHello() retrieves and stores the members of groupName in a list called groupUsers and then checks to see who has left this group since the last invocation of sayHello().

Problem: How can sayHello determine who has left the group since the last time it was called?

Attempted solution:

Store a copy of groupUsers somewhere, so that sayHello() can access it the next time it is called. I'm not sure where to store the list, though. Possible solutions:

  1. Store the list in a class variable.

    But I'm not sure if this value will be reset each time the flow is triggered.

  2. Store the list in a picklist field (this is the approach shown in the code above).

    There is a sayHelloSettings object that stores information about the groups that sayHello() is called on, so I was thinking I could save the list in a picklist field on that object.

    But is it possible to store a list of type List<GroupMember> in a picklist field?

    Also, picklists have a limit of 150, so not a very general solution.

  3. Store the list in a flow variable.

    Is it possible to create/update this variable programmatically inside sayHello()?

I prefer solutions (1) or (2), but I'm not sure if they're antipatterns and was wondering if there's a better solution out there.

Alternatively, is there a way to check membership history for a public group? This would be the ideal solution, as I wouldn't have to save the list.

  • 1
    What's the purpose of this question? What exactly are you trying to achieve? Please see the X-Y Problem.
    – sfdcfox
    Feb 27 at 15:51
  • consecutive executions of an apex invocable method - I'd use sobjects to preserve the state - save it as JSON
    – cropredy
    Feb 27 at 23:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy