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
iswarya sekar 7iswarya sekar 7 

how to display opportunity fields as dropdown in VF page

HI,

I need to display opportunity fields as dropdown in VF page. can anyone suggest me the idea?
PINKY REGHUPINKY REGHU
Hi,
Try this code:
vf page:
<apex:page sidebar="false" controller="sObjectdisplay">
<apex:form >
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!OppNames}">
</apex:selectOptions>
</apex:selectList>
</apex:form>
</apex:page>

controller:
public with sharing class sObjectdisplay {
    public List<selectOption> oppflds;
    public sObjectdisplay(){}
        public List<selectOption> getOppNames() {
            oppflds = new List<selectOption>();
            oppflds.add(new selectOption('--none--','--none--'));
            Schema.DescribeSObjectResult opp_desc = Opportunity.sObjectType.getDescribe(); 
			Map<String, Schema.SObjectField> opp_fields = opp_desc.fields.getMap();
			for(Schema.sObjectField fld:opp_fields.values())
            { 
    				String oppfldName = String.valueOf(fld);
					oppflds.add(new selectOption(oppfldName,oppfldName));
			}
			System.debug('stdObjectNames: ' + oppflds);
            return oppflds;
   		}
}

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
iswarya sekar 7iswarya sekar 7
hey Pinky!!

Thank you so much...