Play Games

Search This Blog

Tuesday, June 2, 2020

Display object names as picklist or drop-down in visual force page

Display object names as drop-down in visual force page.
Apex Class:

public class ObjectNameAsPicklistController {
    public List<SelectOption> lstObject {get;set;}
    public String selectedObject {get;set;}
    public ObjectNameAsPicklistController() {
        lstObject = new List<SelectOption>();
        for(String obj:schema.getGlobalDescribe().keyset()) {
            system.debug('obj:'+obj);
            lstObject.add(new selectOption(obj,obj));
        }
    }
    
}
Page:ObjectAPINameAsPicklist
<apex:page controller="ObjectNameAsPicklistController">
<apex:form>
    <apex:pageBlock>Select Object:<br/>
        <apex:selectList value="{!selectedObject}" label="Select Object:" title="Select Object:">
            <apex:selectOptions value="{!lstObject}"/>
        </apex:selectList>
    </apex:pageBlock>
</apex:form>
</apex:page>

Output:

No comments:

Post a Comment