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
MXMX 

Compare two lists of Select Options

Hey there,

 

I want to create a list of all Objects in my Org and then filter them by my definied List, how can i do this?

 

So I have created a list of all Objects like this:

 

public List<SelectOption> getName(){
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
for(Schema.SObjectType f : gd){
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
}
return options;
}

 

This actually works fine.

But I'd like to create a filter, so i made this List of Selectoptions:

 

public List <SelectOption> testObjects = new List <SelectOption>();

public TestOverrideSettingController(ApexPages.StandardController stdController){
testObjects.add(new SelectOption('Event','Event'));
testObjects.add(new SelectOption('Account','Account'));
testObjects.add(new SelectOption('Contact','Contact'));
}

 

But now I don't know how to go on and compare the Elements in the 2 Lists to each other.

 

Thanks a lot for every help.

Best Answer chosen by Admin (Salesforce Developers) 
Shiv ShankarShiv Shankar

Mx as far as i understood you have two list of select option with you, and you want another list of selctoption, this 3rd selectOption List should contain the option which is comnan in both.

 

for this we can do something like this

 

for(SelectOption so : options){
      for(SelectOption s : testObjects){
               if(s.getLabel() == so.getLabel() && s.getValue() == so.getValue()){
                     thirdSelectOptionList.add(new SelectOption(s));
               }
      }
}

 

 

All Answers

Shiv ShankarShiv Shankar
Can you explain what you are doing in filtration ?
MXMX

I hope I understand correctly what you mean.

 

There is no Filtration yet, I just created those two Lists of SelectOptions and i want those SelectOptions in the Lists, that are equal in both lists.

Shiv ShankarShiv Shankar

Mx as far as i understood you have two list of select option with you, and you want another list of selctoption, this 3rd selectOption List should contain the option which is comnan in both.

 

for this we can do something like this

 

for(SelectOption so : options){
      for(SelectOption s : testObjects){
               if(s.getLabel() == so.getLabel() && s.getValue() == so.getValue()){
                     thirdSelectOptionList.add(new SelectOption(s));
               }
      }
}

 

 

This was selected as the best answer
MXMX

this is exactly what i looked for, thank you a lot!