Convert Set to String
Option 1:

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set<Id> accId = new Set<Id>(); | |
for(Account acc : [SELECT Id, Name FROM Account LIMIT 10]) { | |
accId.add(acc.Id); | |
} | |
system.debug(accId); | |
String str = ''+accId; | |
system.debug(str); |
Drawback: once the set size increase above option to convert the set to string as it receives i.e.
Option 2:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set<Id> accId = new Set<Id>(); | |
for(Account acc : [SELECT Id, Name FROM Account LIMIT 100]) { | |
accId.add(acc.Id); | |
} | |
List<Id> strList = new List<Id>(accId); | |
system.debug('strList: ' + strList); | |
String str = string.join(strList, ','); | |
system.debug('String value : ' + str); |
output: