[SalesForce] Retrieve Picklist values when using Visualforce Remote Objects

Is there a way to get all Pick list values for a custom field / object using Remote Objects? I have looked at the docs, tried querying the fields but not sure how I can do this. Any guidance or pointers will be appreciated.

Best Answer

Yes.

<apex:includeScript value="/soap/ajax/36.0/connection.js"/>
<apex:remoteObjects>
    <apex:remoteObjectModel name="Opportunity" fields="Id,Stage"/>
</apex:remoteObjects>

<script>
var result = sforce.connection.describeSObject("Opportunity");

for (var i = 0; i < result.fields.length; i++) {
    if (result.fields[i].name === 'Stage') {
        var field = result.fields[i];
        for (var j = 0; j < field.picklistValues.length; j++) {
            html += '<option value="' + field.picklistValues[j].value + '">' + field.picklistValues[j].value + '</option>';
        }
    }
}
</script>
Related Topic