3

Does anyone know why below code returns me with only 1 record

set<account> myset = new set<account>([select id  from account limit 100]);
system.debug('SETTT' + myset);

But when i say 'Name' to retrieve ,it gives me complete list.

set<account> myset = new set<account>([select id ,name from account limit 100]);
    system.debug('SETTT' + myset);

Find it strange,as ID is a unique thing and set should display all records

7

This is purely an anomaly of how the string representation of set looks when you System.debug it. All values are there for you to use in code. Try:

set<account> myset = new set<account>([select id from account limit 100]);
system.debug('SET string representation = ' + myset);
system.debug('SET size = ' + myset.size());
for (account a : myset) {
    System.debug('an account id = ' + a.id);
}
  • Okeis.i found it strange as the same thing with map/list showed all values.But as in above code .yeah it does have everything – sfdc99999 Jul 3 '13 at 14:49
  • You are right, it does look different with name vs. id but this is just in the debug. – Doug B Jul 3 '13 at 14:54
  • FYI this is still an issue as of 2018. – torpy Aug 31 '18 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.