Find your content:

Search form

You are here

What is the best way to add to an apex collection of String

 
Share

Is there a more efficient way to Select data into a String collection e.g. Set<String> than using a for loop

Set<String> allTopicSet = new Set<String>();    
for (Topic t: [select name from Topic]) {
    allTopicSet.add(t.Name);
}

Attribution to: collymitch

Possible Suggestion/Solution #1

There isn't, you can only get the Id of a list of objects easily by converting the list to a map and getting the keyset. (See I just want the IDs?)

I'm afraid you're stuck to looping over the list, and adding them manually like you are doing now.


Attribution to: pjcarly
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31500

My Block Status

My Block Content