+ Start a Discussion
Saransh Bharadwaj 1Saransh Bharadwaj 1 

Field Schema on VF page without use of controller

Hi Guys,

I want to fetch out picklist field values on visualforce page. These picklist values are already defined at object level. So for ex: I have an object called custom__c and field over it is permission__c(Picklist field) with values [Read;Write;No Access].
Now without using controller, can I print these 3 values on visualforce page?


Without using Controller, you can leverage <apex:inputfield> and map it to the picklist.

Using javascript you may hide the element and display the values under the picklist in any so desired fashion.
Saransh Bharadwaj 1Saransh Bharadwaj 1
Hi Sanjay,

I can't use inputfield because in that case, I would require to use <apex:form>, and I don't want to use it. 
Can we use $ObjectType global variable to fetch picklist value somehow? or if anyother way we have to acomplish this.

Hi Saransh,

Unfortunately you can't directly use Sobject describe to fetch picklist values. If you can explain the use case, I might be able to help you with an alternate solution.

If you ready to put some extra effort, you can retreive all the picklist information using Sobject API by hitting salesforce API again from VF page using Javascript. This will fetch you the picklist values from the following endpoint:
URL : /services/data/v33.0/sobjects/Account/describe


Authentication : Bearer <SessionID>

Saransh Bharadwaj 1Saransh Bharadwaj 1
This exactly what i was looking for.
Let me tell you what my case is: I am trying to create a single page application without use of controller, so to avoid controller i am using remoteObjects, Javascript combination to achieve it. I have a custom object which could expand with some more picklist fields in future. So to make it flexible, I was fetching schema previously and returning map of picklist field name and their values but this one I achieved through controller which is something I don't want it now.

If you could give me some piece of code by explaining a way of fetching picklist value by taking an example of Account object and Industry(Picklist) field through /services/data/v33.0/sobjects/Account/describe , which will going to return a JSON string. In your example if you could explain me how to display those values would give me a great help on my current page.

Thanks in Advance!