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
basha skbasha sk 

How to filter previous values from next response values ?

            Hi All,

            I'm trying to filter the below mentioned response like below please check it once

              Map<String,String> customsettingValues = new Map<String,String>();
              Map<String,String> SelectedValues = new Map<String,String>();
              Set<String> orderList1 = new Set<String>();
              for(String firstKey : customsettingValues.keySet()){                     
                  String firstValue = customsettingValues.get(firstKey);                    
                for(String secondKey : SelectedValues.keySet()){                      
                    String secondValue = SelectedValues.get(secondKey);                      
                       if(firstValue.equals(secondKey)){
                            
                           orderList1.add(secondValue);
                           System.debug('orderList1:::---------'+orderList1);
                                                                    
                  }
                }
              }

            I got the Response Like below for the above code

            orderList1:::---------{chandra}
            orderList1:::---------{chandraiii@gmail.com,chandra}
            orderList1:::---------{Not Attended,chandraiii@gmail.com,chandra}
            orderList1:::---------{vizag,Not Attended,chandraiii@gmail.com,chandra}
            orderList1:::---------{ap,vizag,Not Attended,chandraiii@gmail.com,chandra}
            orderList1:::---------{Ind,ap,vizag,Not Attended,chandraiii@gmail.com,chandra}
            orderList1:::---------{88888888888,Ind,ap,vizag,Not Attended,chandraiii@gmail.com,chandra}

            How to change above response like below

            orderList1:::---------{chandra}
            orderList1:::---------{chandraiii@gmail.com}
            orderList1:::---------{Not Attended}
            orderList1:::---------{vizag}
            orderList1:::---------{ap}
            orderList1:::---------{Ind}
            orderList1:::---------{88888888888}

            If anybody having idea please let me know

            Thanks In Advance
            Basha
Best Answer chosen by basha sk
Sohan Raj GuptaSohan Raj Gupta
Hi Basha,

Try below update code:
 
Map<String,String> customsettingValues = new Map<String,String>();
        Map<String,String> SelectedValues = new Map<String,String>();
        Set<String> orderList1 = new Set<String>();
        
        for(String firstKey : customsettingValues.keySet()){                     
            String firstValue = customsettingValues.get(firstKey);
            
            if(SelectedValues.containsKey(firstValue)){
                System.debug('orderList1:::---------'+SelectedValues.get(firstValue));
            }
        }

I hope this will help you.

Thanks,
Sohan Raj Gupta

All Answers

Sohan Raj GuptaSohan Raj Gupta
Hi Basha,

Your code is correct. You have written System.debug('orderList1:::---------'+orderList1); in FOR loop thats why you got below response in debug:
     orderList1:::---------{chandra}
     orderList1:::---------{chandraiii@gmail.com,chandra}
     orderList1:::---------{Not Attended,chandraiii@gmail.com,chandra}
     orderList1:::---------{vizag,Not Attended,chandraiii@gmail.com,chandra}
     orderList1:::---------{ap,vizag,Not Attended,chandraiii@gmail.com,chandra}
     orderList1:::---------{Ind,ap,vizag,Not Attended,chandraiii@gmail.com,chandra}
     orderList1:::---------{88888888888,Ind,ap,vizag,Not Attended,chandraiii@gmail.com,chandra}

But if you check SET collection size then it will show 7. If you want still same response which you want then you can use simple STRING instead of SET.

Please let me know if it helped or you need any more assistance.

Please mark this is as the solution if it solved your purpose.

Thank You,
Sohan Raj Gupta
basha skbasha sk
@Sohan Raj Gupta thanks for giving the response please update the my question with some changes for the required output i will check beacuse i tried in somany ways .Thanks
Sohan Raj GuptaSohan Raj Gupta
Hi Basha,

Try below update code:
 
Map<String,String> customsettingValues = new Map<String,String>();
        Map<String,String> SelectedValues = new Map<String,String>();
        Set<String> orderList1 = new Set<String>();
        
        for(String firstKey : customsettingValues.keySet()){                     
            String firstValue = customsettingValues.get(firstKey);
            
            if(SelectedValues.containsKey(firstValue)){
                System.debug('orderList1:::---------'+SelectedValues.get(firstValue));
            }
        }

I hope this will help you.

Thanks,
Sohan Raj Gupta
This was selected as the best answer
basha skbasha sk
@Sohan Raj Gupta you are printing secondkey details I don't want second key details ,Here I want to print second value details ilke abobe required response.please check like that way once Thanks
basha skbasha sk
@@Sohan Raj Gupta Excellent I got the response like what how Iwant is it possible to read response like orderList1[0],orderList1[1]........like that.Thanks
basha skbasha sk
Not required Sohan I have completed that part .Thanks for your help