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
SFDC ADM 7SFDC ADM 7 

Populate list values into apex:selectoptions

Hi All,
I am getting record types by using below list

List<RecordType> recList= new List<RecordType>([select id, name from recordtype where sobjecttype='obj1__c']);

I want to show this values in apex:select. How can I do this

I tried some ways, but not working.
Please help me

Thanks in Advance!!

v varaprasadv varaprasad
Hi ADM,

Please check once below sample code : 
public class Recordtypes {
    public list<selectoption> lstOfRectypes{set;get;}
    List<RecordType> recList;
    
    public Recordtypes(){
        lstOfRectypes =  new list<selectoption>();
        lstOfRectypes.add(new selectoption('None','None'));
        recList= new List<RecordType>([select id, name from recordtype where sobjecttype='Lead']);
        for(RecordType rd : recList){           
            lstOfRectypes.add(new selectoption(rd.name,rd.name));
        }
    }
}

====================
<apex:page controller="Recordtypes">
    <apex:form>
        <apex:pageBlock title="Recordtypes">
            <apex:selectList size="1">
                RecordTypes :  <apex:selectOptions value="{!lstOfRectypes}">
                </apex:selectOptions>
            </apex:selectList>
        </apex:pageBlock>
    </apex:form>
</apex:page>

===============

Hope this helps you.

Thanks
Varaprasad