2

Can you populate a set from a soql query? I couldn't get my syntax to work

Set c = [select id From Contact limit 1000 ];

thanks!

PartOfTheOhana
  • 667
  • 2
  • 16
  • 40

1 Answers1

10

You need to declare the type of your set and make use of the set constructor that takes a list as a parameter giving you something like this:

Set<Contact> c = new Set<Contact>( [SELECT Id, Name FROM Contact LIMIT 1000] );
Simon Goodyear
  • 416
  • 4
  • 8