Just interesting behaviour.

I want to write method:

public User[] getUsersByIds(Iterable<Id> userIds) {
    return [
        SELECT Id
        FROM User
        WHERE Id in :userIds

But during save I receive this message

IN operator must be used with an iterable expression

I'm confused.


More interesting that Set<Id> does not implement Iterable<Id>

Now I'm twice as confused!

  • Just curious, why are you using Iterable at all?
    – Adrian Larson
    Aug 25, 2016 at 15:35
  • @AdrianLarson I use IDE that not released (and try to find some bugs and help to developers team), and just find this.
    – misha_m
    Aug 25, 2016 at 17:53

1 Answer 1


Why? This question is going to be very difficult to answer. Clearly the error message could use improvement, as you have noted based on the fact that the IN operator accepts Set<Id>.

Likely this omission is just an oversight by the development team. They probably found it an unlikely use case that someone would use an Iterable<Id> where List<Id> and Set<Id> and even List<SObject> are available for use. In the abstract, use of Iterable<Id> here seems over-engineered. If you really want support for use of Iterable<Id>, you should create an Idea and wait a few years for it to gather dust.

If you're committed to using Iterable<Id> in your method signature, you can build the list yourself by iterating through it.

public List<User> getUsersByIds(Iterable<Id> userIds)
    List<Id> ids = new List<Id>();
    Iterator<Id> i = userIds.iterator();
    while (i.hasNext()) ids.add(i.next());
    return [SELECT Username FROM User WHERE Id IN :ids];
  • 2
    The data used in a query needs to be serializable assuming the query is run in a separate process and the object that implements Iterable could easily not be.
    – Keith C
    Aug 25, 2016 at 16:27
  • Ah, fair enough. Whereas those other supported types are known to be serializable. You should post an answer @Keith!
    – Adrian Larson
    Aug 25, 2016 at 16:28

You must log in to answer this question.

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