Questions tagged [collection]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
19
votes
1answer
487 views

Is there a specific reason why we can't upcast Sets?

As most stories here begin, I was writing some code for a project that I was working on, and stumbled across an oddity when writing some unit tests. I was testing a method that has a Set<sObject>...
18
votes
3answers
3k views

Do Apex collections implement iterable?

Do Apex collection classes implement Iterable interface? I want to write a generic function that can take any of the collection classes that support foreach. Is this possible?
18
votes
4answers
3k views

Critical update: “Predictable Iteration Order for Apex Unordered Collections” documentation

Today in one of my sandboxes, I was overjoyed to see the following critical update: "Predictable Iteration Order for Apex Unordered Collections" - The iteration order of unordered collections (maps ...
22
votes
4answers
9k views

Convert a Set<Id> to Set<String> using Apex

I have a Set<Id> which I want to convert to a Set<String>. I don't want to use a for loop to iterate over it. What is the simplest way to do this?
14
votes
2answers
7k views

Map<ID, Map<string, Map<ID, List<PricebookEntry>>>> Good practice or bad?

I have a question about APEX programming practices. My problem: I'm moving a SOQL query out of a for loop in an algorithm to allow for more processing per execution context. The SOQL queried ...
11
votes
2answers
4k views

How to write a generic list<t> method that will cast at runtime?

I recently tripped across the need to take a list of objects (instances of a class--not sobjects) and split them into smaller lists of 200 members each. The unit test below shows the code inside a ...
6
votes
1answer
148 views

iterator() on a set. Reason for it not being in the Apex Doc?

Although not documented as a set method, iterator() seems to work just fine on sets: set<String> strings = new set<String> {'a','b'}; system.debug(LoggingLevel.INFO,'next() on set ='+...
6
votes
1answer
212 views

Doesn't Set<T> collection implement Iterable<T> interface? [duplicate]

I am trying to join String elements of Set with semicolon. Set<String> elements = new Set<String>{ 'foo', 'bar' }; System.debug(String.join(elements, ';')); getting the ...
5
votes
1answer
1k views

include component seems to be having issues with merge-field syntax inside of a repeat component

I am trying to place an apex:include inside of an apex:repeat component. But I am getting a compile error: <apex:repeat value="{!placeholders}" var="placeholder"> {!placeholder} - {!...
4
votes
2answers
295 views

SOQL For Loop Architecture Question

I have a pretty simple/general question, out of the two approaches below, what is the best method when querying and looping over a collection? Approach 1: for(Account a : [SELECT Id, Name FROM ...
3
votes
2answers
4k views

Collection of List<sObjects> keyed by sObject field

Is it possible to have a Map (or other collection) of sObjects list, keyed by one lookup field of the same sObject. Something like Maps of sObjects (below code doesn't works): Map<Id, List<...
1
vote
1answer
1k views

Error:Loop must iterate over a collection type: User

I am getting error saying'Loop must iterate over a collection type: User'.I am not able to find what actually error wants to say. List<User> listUserDeactivate = new List<User>(); Set<...
14
votes
2answers
7k views

Performance: List.get(index) vs List[index]

I want to know which approach is better in Salesforce when getting element from list. Is this faster? myList.get(0); Or is this faster? myList[0]; Using large list which above statement is more ...
4
votes
1answer
427 views

Pass Case Ids collection to visual workflow from Case List View Custom Button and update cases taking from input screen

Requirement From Case list View, user will choose one or more cases and will click on "Update Due Date" button, where it will show a screen to choose the "Due Date". Due Date screen And finally ...
1
vote
1answer
61 views

Do Maps have an Reliable Relationship between keySet() order and values() order?

Let's say I have a map, for example: Map<SObjectField, SObjectField> valueByKeyMap Assuming neither the Map nor its contents are mutated by other activity in the system, can I rely on these ...
1
vote
2answers
5k views

How to fill a map with the object field as key from the query? [duplicate]

I'm doing a query to an sObject with Dynamic apex and I would like to store al keys and values in a map where the map contains the object field as key and the value of that field from my query looking ...