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
Hermann OuréHermann Ouré 

Add Set Ids to a String Variable

Hello,
I am trying to use the Ids that I store in a Set; in a String variable but I am unable to do so.
I have obviously an error: Variable Id does not exist. But I don't j=know how to fix it.
Could someone help?
Thanks

here is what I wrote:
public static String setSlackUserNickName(String businessUnit) {
        String channelName;
        Set<ID> headOfService_ids = new Set<ID>();
        
        Map<Id, Application_Parameters__c> headOfService = New Map<Id, Application_Parameters__c>(
            [SELECT Id, Head_of_Service__c FROM Application_Parameters__c WHERE Business_Unit__c = :businessUnit]);
     
        for(Application_Parameters__c app : headOfService.values()) {
            headOfService_ids.add(app.Head_of_Service__c);
        }
       
         
        channelName = ''+headOfService_ids.get(Id).CommunityNickname+'';

 
AnudeepAnudeep (Salesforce Developers) 
Hi Hermann, 

I am suspecting the issue is occurring at the following line

channelName = ''+headOfService_ids.get(Id).CommunityNickname+'';

Try passing a dynamic value instead of id because id is not defined as a variable anywhere in your class

like headOfService_ids.get(app.Head_of_Service__c)

I recommend adding a system.debug to your code and see what values are being retrieved 
 
Map<Id, Application_Parameters__c> headOfService = New Map<Id, Application_Parameters__c>( [SELECT Id, Head_of_Service__c FROM Application_Parameters__c WHERE Business_Unit__c = :businessUnit]);

// After populating the map, iterate through the map entries
for (ID idKey : headOfService.keyset()) {
    System.debug('map value' + headOfService.get(idKey));
}

Let me know if this helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep