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
anu123anu123 

is it possible to create the fields under the particular object using vf pages and controller

Hi all,

     I want to create the picklist field under the particular object  dynamically.is it possible?

if possible any one can u please give me the sample code.

 

thanks in advance.

anu

Best Answer chosen by Admin (Salesforce Developers) 
Rajesh_SFGRajesh_SFG

fine.. picklist default functionality is show the options value. There are two possible to returned the options values one is fixed value from visualforce page another one returned the list values from controller class.

Controller class example:

public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        for(Demo_Product__c products:[Select Name from Demo_Product__c]){              
           options.add(new SelectOption(products.Name,products.Name));
        }
        return options;
    }   

visualforce page:

        <apex:selectList value="{!Product1}">
           <apex:selectOptions value="{!Items}"/>
        </apex:selectList>



All Answers

Rajesh_SFGRajesh_SFG

can you explain picklist mean dropdown(combo textbox) or lookup field.

anu123anu123
Hi, thank u for ur reply. picklist means its a dropdown list.
Rajesh_SFGRajesh_SFG

fine.. picklist default functionality is show the options value. There are two possible to returned the options values one is fixed value from visualforce page another one returned the list values from controller class.

Controller class example:

public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        for(Demo_Product__c products:[Select Name from Demo_Product__c]){              
           options.add(new SelectOption(products.Name,products.Name));
        }
        return options;
    }   

visualforce page:

        <apex:selectList value="{!Product1}">
           <apex:selectOptions value="{!Items}"/>
        </apex:selectList>



This was selected as the best answer