function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swapna muthiyaluswapna muthiyalu 

how to create set for sobject and print it?

Best Answer chosen by swapna muthiyalu
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi swapna,
you can use like this,

for(Account acc : accountSet) { 
    system.debug(acc.name);
}

regards,
prosenjit

All Answers

Prosenjit Sarkar 7Prosenjit Sarkar 7
HI Swapna, 

this code snippet may help you , 
 
Set<Account> accountSet = new Set<Account>();
accountSet = new Set<Account>([SELECT Name FROM Account LIMIT 4]);
System.debug(accountSet);

Thanks, 
Prosenjit
swapna muthiyaluswapna muthiyalu
Hi Prosenjit,
Thank you so much. Its working fine.is it possible to print using for loop for set?
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi swapna,
you can use like this,

for(Account acc : accountSet) { 
    system.debug(acc.name);
}

regards,
prosenjit
This was selected as the best answer
swapna muthiyaluswapna muthiyalu
Thanks Prosenjit...