+ Start a Discussion
himanshu huske 7himanshu huske 7 

Set And Map

hi, I m a bigginer, I want to insert set of record in object. how set of sobject is converted into list ?  How to update those records?
Same for Map.
  Please help me with it.
DivyanshD SinghDivyanshD Singh
Set<String> setStrings = new Set<String>{'hey','hello'};
 List<String> listStrings = new List<String>(setStrings);

Hope this helps.
​​​​​​​Thanks
Ravi Dutt SharmaRavi Dutt Sharma
You do not insert a set of records. You create a list of records and then insert the list. See below example:
List<Account> accList = new List<Account>();
accList.add(new Account(Name='Test Account'));
insert accList;

 
Ajay K DubediAjay K Dubedi
Hi Himanshu,

Try out the following code it may be helpful:
Set<String> strSet= new Set<String>();
        for(Account acc:[Select Name From Account Limit 5]){
        strSet.add(acc.Name);
        }
        
        List<String> sObjectList = new List<String>();
        for(String i :strSet){
        sObjectList.add(i);
        }
        system.debug('sObjectList->'+sObjectList);       
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi