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
Siana DcruzSiana Dcruz 

How to map label names to picklist values of two different objects.

Hi all,

In the below code, I am mapping
 label1 to time1,
 label2 to time2,
 label3 to time2,
 label4 to time3
 All these are the picklist values in the field time__c. Now i want 
 1)label2 to be mapped to 'time2'(which is done) and also to 'reason2' picklist value of reason__c field.
 2)label3 to be mapped to 'time2' of time__c field and 'reason3' of reason__C field.
 
 Anyone Please suggest me how can I achieve this.
 
 public List<SelectOption> getTimeOptions()
    {
        List<SelectOption> options = new List<SelectOption>();
        List<String> times= this.getDynamicPicklistValues('Intake__c', 'time__c');
       // List<String> reasonTypes = this.getDynamicPicklistValues('Intake__c', 'Reason__c');
        for (String time: times)
        {
          if(time== 'time1')     
              options.add(new SelectOption(time,'label1'));
           
         if(time== 'time2')  
             options.add(new SelectOption(time,'label2'));
       
          if(time== 'time2')  
             options.add(new SelectOption(time,'label3'));
       
        if(time== 'time3')  
           
             options.add(new SelectOption(time,'label4'));
              
         }
 return options;
     }
     
UC InnovationUC Innovation
Seems like you just need to create another function to return the Reason__c options?
 
public List<SelectOption> getReasonOptions()
{
	List<SelectOption> options = new List<SelectOption>();
	List<String> reasonTypes = this.getDynamicPicklistValues('Intake__c', 'Reason__c');
	for (String reason: reasonTypes)
	{         
		if (reason== 'reason2')  
			options.add(new SelectOption(reason,'label2'));
   
		if (reason== 'reason3')  
			options.add(new SelectOption(reason,'label3'));
		  
	}
	
	return options;
 }

Then, call getTimeOptions() and getReasonOptions() separately.

If you need to return both Reason and Time options within the same function, then you need to change the return type 'List<SelectOption>' to either a 'Map<String, <List<SelectionOption>>>' where the key would be either 'Time' or 'Reason', for example, or a 'List<List<SelectionOption>>' and add the Time and Reason options list to it.
 
Siana DcruzSiana Dcruz
UC Innovation, yes I want both reason and time options within the same function. I am calling this function from the vf page as

<apex:selectRadio styleClass="FeedTypeRadio"  value="{!Intake__cTime_c}" layout="pageDirection" label="" required="false">  <apex:selectOptions value="{!TimeOptions}" />
  </apex:selectRadio>

If I prefer to use List<List<SelectionOption>> as you said, Whether I need to change anything in my vf page?.Can you please provide me a sample to use List<List<SelectionOption>> type in my method.
UC InnovationUC Innovation
Are you trying to show the Reason and Time options in one select list, or two in the VF page?