Set does have an iterator method; this is used internally by the for-in loop syntax. However, it does not implement the Iterable interface.
This notably means that new methods, like String.join, do not work with Sets, even though they have the iterator method.
As far as the documentation is concerned, I suspect that it's not documented because Set doesn't actually implement the Iterable interface. In other words, it's an internal method.
You'll also notice that other methods are not documented, either. For example, Object isn't documented, despite having two methods you can use (equals and hashCode).
I'm not sure you'd get a better answer short of having a real salesforce.com employee posting an answer.
Answer from sfdcfox on Stack Exchange13:13
How to master for loops in Apex Salesforce for Lists, Sets, and ...
10:40
#14 Apex List or Set Iteration for Loops | For Each Loop | Enhanced ...
53:05
Collections and looping in apex || List, Set, Map || For loop, ...
Salesforce Apex Master Class (Ep. 30) - Collection Iteration Best ...
forceapozee
forceapozee.com โบ post โบ mastering-iteration-in-apex-using-iterable-for-simplified-loops
Mastering Iteration in Apex: Using Iterable for Simplified Loops
January 30, 2025 - Here, the MyIterable class implements Iterable<String>, and the iterator() method returns a set iterator. This makes it easy to reuse and customize iterable objects across different scenarios. Improved Code Readability: Using Iterable makes loops more intuitive and clean. Reusability: Custom implementations of Iterable allow flexible iteration logic. Consistency: Ensures a standard approach to iterating over collections in Apex.
Salesforce
help.salesforce.com โบ s โบ articleView
Iterate Within For Loops More Easily with Iterable | Salesforce Help
This example implements an Iterable ... MyIterable implements Iterable<String> { public Iterator<String> iterator() { return new Set<String>{'Hello', 'World!'}.iterator(); } } for (String str : new MyIterable()) { System.debug(str); } IdeaExchange: Allow Iterable for Loops in ...
Blogger
salesforcecodes.blogspot.com โบ 2020 โบ 01 โบ how-to-use-custom-iterator-in-apex.html
Salesforce Codes: How to use custom iterator in apex batch class
Use a custom iterator defined using CustomIterable interface ยท You can just use standard apex collections like list as iterator.
Medium
medium.com โบ @anuhyadigital โบ what-is-interface-iterator-in-apex-bbb987509d0c
What is Interface Iterator in Apex | by Anuhya digital | Medium
September 30, 2024 - An Iterator is a design pattern in Apex that provides a way to access the elements of a collection sequentially without exposing its underlying representation. It allows developers to traverse through data, one element at a time, making it particularly useful when working with large data sets in Salesforce.
Comrevo
comrevo.com โบ 2023 โบ 01 โบ apex-list-or-set-iteration-for-loops.html
Comrevo โ Free Calculators + Tech Guides: Apex List or Set Iteration for Loops | For Each Loop | Enhanced or Range Based For Loop | Salesforce
January 8, 2023 - In this post, we will see Apex List or Set Iteration for Loops | For Each Loop | Enhanced or Range Based For Loop | Salesforce
Wordpress
suhasrathod.wordpress.com โบ 2020 โบ 04 โบ 10 โบ how-to-use-custom-iterator
How to use custom iterator
April 10, 2020 - global class CustomIterable implements Iterator<Account>{ List<Account> accs {get; set;} Integer i {get; set;} public CustomIterable(){ accs = [SELECT Id, Name, NumberOfEmployees FROM Account WHERE Name = 'false']; i = 0; } global boolean hasNext(){ if(i >= accs.size()) { return false; } else { return true; } } global Account next(){ if(i == 8){return null;} i++; return accs[i-1]; } } ... global class example implements iterable<Account>{ global Iterator<Account> Iterator(){ return new CustomIterable(); } }
YouTube
youtube.com โบ codeisha
Custom Iterator in Apex | Benefits, Methods & Code Example - YouTube
Learn everything about Custom Iterators in Apex:1. What is a Custom Iterator?2. Why should you use Custom Iterators?3. Where can you implement them?4. Key me...
Published: December 29, 2024
Views: 200
Salesforce
ideas.salesforce.com โบ s โบ idea โบ a0B8W00000GdX2vUAF โบ apex-code-implement-iterable-on-set
Apex Code: Implement Iterable on Set. - IdeaExchange
Loading ยท รSorry to interrupt ยท Refresh