Wednesday, 17 April 2013
Display sObject Fields list in picklist of visualforce page without using controller
If you want to display picklist with any sObject field list in your visualforce page. you can do it using javascript without using Apex controller. No need to write class.
Here is the example for displaying all the field of Account in picklist.
Visualforce Page:
<apex:page>
<apex:includeScript value="/soap/ajax/16.0/connection.js"/>
<label id="ldfield" style="font-weight:bold">Account Fields: </label>
<select id="selectNumber">
</select>
<script>
sforce.connection.sessionId = '{!$Api.Session_ID}';
//Global Object
var describeResults = sforce.connection.describeSObject("Account");
//select option list
var select = document.getElementById("selectNumber");
for(var i = 0; i < describeResults.fields.length; i++) {
var fieldList = describeResults.fields[i];
var el = document.createElement("option");
el.textContent = fieldList.label;
el.value = fieldList.Name;
select.appendChild(el);
}
</script>
</apex:page>