1

Can someone let me know if there is a better way of coding this?

I want to pass one ID to the class from a Visual Flow, which is the ID of the current user, and then get back a count of the records found. I don't need the lists but I can't get the class to accept anything other than a list for input and output.

There must be a better way!

 global class getUnnasociatedCallCount {

       @InvocableMethod
       public static list<string> getRecordCount(List<Id> UserIds) {      
        Integer callcount = [Select Count()
                    FROM Task
                    WHERE Status = 'In Progress'
                    AND WHATID = NULL
                    AND RecordType.Name = 'Five9 Call'
                    AND OwnerID = :UserIds];

        list<string> calllist = new list<string>();
        CallList.add(string.valueof(callcount));
        return callList;
       }
    }
3
  • 1
    As it is, consider changing OwnerID = :UserIds to OwnerID in :UserIds. May 29, 2018 at 21:27
  • 1
    @DanielBallinger Any reason why? It compiles either way.
    – sfdcfox
    May 29, 2018 at 23:52
  • @sfdcfox True, both work. I'd say using IN rather than = because it more closely aligns to have the comparison operations are defined. It is clearer that the owner ID is in the collection rather than equals the collection. May 30, 2018 at 0:02

1 Answer 1

2

You must use a List for both input and output, because these methods can be called from different places, and must therefore accept the possibility that they will be used on multiple parameters.

There's a REST API call for them, and you can call them from flows (including Process Builder). By requiring a List, the system enforces the general principle that you should be designing your code to be optimized and bulkified.

You must log in to answer this question.

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