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
Néstor Velázquez SánchezNéstor Velázquez Sánchez 

How to show a specific picklist by the record type

Hi, I have a big problem. 

I have an OptionList, this OptionList come from a bigest query: 
 
/* CONTROLLER */
optiones = [SELECT someFields myField__r.RecordTypeId FROM myCustomObject__c WHERE (myField__r.RecordTypeId=: RTPersonalProduct2 OR myField__r.RecordTypeId=: RTMusicProduct2) AND myField__c IN: theList AND otherField__c NOT IN: mapAssetsProduct.keySet() AND myField__c NOT IN (SELECT myField__c FROM Booking__c WHERE ((dateStart__c >=: listDates1) AND (Fecha_fin__c <=: listDates2)) AND (hour__c	IN: hourStarList AND hour2__c IN: hourFinalList) )];


for(object__c r: optiones)
{
options.add(new SelectOption (r.myField__c, r.Product__r.Name));
}


/* Visual Force Page */
<apex:selectList value="{!asset.substituto}" size="1" multiselect="false" >
    <apex:selectOption itemLabel="-- SELECCIONA UN SUSTITUTO --" itemValue="" />
    <apex:selectOptions value="{!options}" />                              
</apex:selectList>


Where asset.substituto is a Map:   Map<String, List<>> ​ 

 

The issue is: I want use an selectList ONLY for a RecordType = RTPersonalProduct2 and display other selectList for the RecordType = RTInstrumentosProduct2 

 

I don't kwon how use the values or the fields to use one or other list, I only get a bigest list with all elements. 

 

If you know how access to the System.SelectOption to manipulate the option value elements, please help me. 

It's really simple if something then whatever but in the visual force it's not possible or I don't know how. 

NagendraNagendra (Salesforce Developers) 
Hi Nestor,

May I suggest you please check with below link from stack exchange community with a similar issue which will point you in the right direction. Please let us know if this helps.

Thanks,
Nagendra
Nestor VelázquezNestor Velázquez

I am coming from future and let teach you how We can did make it:  

1. Create a String public variable. 
 

public String optionSelected { get; set; }

2. Using a public list with the options you fill the options list select: 
public SelectOption[] getTipos()
    {
        return new SelectOption[] { 
            new SelectOption(' --- SELECCIONA UNA OPCIÓN --- ', ' --- SELECCIONA UNA OPCIÓN --- '), 
                new SelectOption('Option 1', 'Option 1'),
                new SelectOption('Option 2', 'Option 2'),
                new SelectOption('Option 3', 'Option 3')
                };
    }

3. In the Visualforce Page use the apex component for SELECT: 
<apex:selectList label="Select option" value="{!optionSelected}" >
      <apex:selectOptions value="{!tipos}"></apex:selectOptions>
</apex:selectList>

This the steps to follow. 
Thanks for reading.