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
kiran2000kiran2000 

convert set to string

Hi,

 

 I need to convert set of ids to string.

 

Set<id> accIdSet = new Set<Id>();

 

I need to contcatinate the string to another string.

 

after processing i need to retreive the set of ids.

 

Can someone show me some example around this.

 

 

Thanks

Dev@Force.ax647Dev@Force.ax647

There are many ways to do convert set into string. See below. Let me know if you need more help.

 

Set<Id> test=new Set<Id>();
for(Account a:[Select Id From account limit 5])
{
     test.add(a.Id);
}
String temp=''+test;//compiler will implicitly convert into string.
system.debug('============='+temp);

 

:) :) :) :) :):) :) :) :) :)

Set<ID> accIDSet = new Set<Id>();

accIDSet = [select id from account ------your SOQL Query--------];

String idString;

 

 for(ID ids : accIDSet)
            {
                idString = ids + userrec.email + ',' ;
            }

idString = idString.substring(0, idString.length()-1);

amarcuteamarcute

Hi,

 

You can use the bellow logic

 

String idStr = '';
for(String s:accIdSet) {
   idStr += (idStr == ''?'':',')+s;
}
sfdcfoxsfdcfox
String joinedString = String.join(new List<String>(accIdSet), ',');