0

I have a picklist on a visualforce page and I'm trying to filter by namespace prefix to display objects belonging to a package as well as the account and contact objects. I have the for loop below that is adding the objects label and api name to the list. I've tried adding an if statement using mapKeys.contains('xyz'), but the options list is empty.

Here is a debug of mapKeys which is a made of the label and api names combined.

[109]|DEBUG|options (62 Org Case (agf__ADM_Case__c), ADM Platform Cache Metadata (agf__ADM_Cache_Metadata__mdt), API Event (ApiEvent), Account (Account), ...).

Any help getting the if statement corrected, or advice would be appreciated.

for(string s: mapKeys){
            if(mapKeys.contains('Account')){
                options.add(new SelectOption(objectLabelToNameMap.get(s),s));  
            }     
        }             
        return options;                                      
    }
  • it would be helpful to show how mapKeys is instantiated as namespace data is available in the Schema.Describe methods – cropredy Sep 11 at 0:31
2

You should be checking "s" instead of mapKeys, and presumably check each value you're interested in:

for(String s: mapkeys) {
  if(s == 'Account' || s == 'Contact' || s.startsWith('agf__')) {

Note that if mapkeys came from a Schema.getGlobalDescribe(), they're always lowercased, so:

if(mapKeys.contains('account')) {

But, this would not do what you expect it to; since the if statement is inside the loop, but checking the loop's iterator, it will always be true, or always false, thus showing nothing or everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.