+ Start a Discussion
vickim1.396005552708281E12vickim1.396005552708281E12 

Retrieve field options via API SOQL

Hi Guys,

I am currently creating a custom form on our personal website, the form mimics the opportunity form, and we create new opportunities from the form submission. 

I need to be able to retrive the Picklist field options from saleforce into our forms dropdown (some of the Picklist fields are custom fields), is there a way to do this, please keep in mind I cant just copy the choices from salesforce to our platform as the admin are always adding new choices to the Picklist in salesforce.


Thank you.
Abhinav GuptaAbhinav Gupta
You can use REST API and Object Describe. 

Make a call to following REST Endpoint

https://na17.salesforce.com/services/data/v30.0/sobjects/Opportunity/describe

It will return you all the field details with required picklist values as well, for ex. Lead Source values will be in this format in JSON response :

{
        "autoNumber": false,
        "byteLength": 120,
        "calculated": false,
        "calculatedFormula": null,
        "cascadeDelete": false,
        "caseSensitive": false,
        "controllerName": null,
        "createable": true,
        "custom": false,
        "defaultValue": null,
        "defaultValueFormula": null,
        "defaultedOnCreate": false,
        "dependentPicklist": false,
        "deprecatedAndHidden": false,
        "digits": 0,
        "displayLocationInDecimal": false,
        "externalId": false,
        "extraTypeInfo": null,
        "filterable": true,
        "groupable": true,
        "htmlFormatted": false,
        "idLookup": false,
        "inlineHelpText": null,
        "label": "Lead Source",
        "length": 40,
        "mask": null,
        "maskType": null,
        "name": "LeadSource",
        "nameField": false,
        "namePointing": false,
        "nillable": true,
        "permissionable": true,
        "picklistValues": [{
            "active": true,
            "defaultValue": false,
            "label": "Web",
            "validFor": null,
            "value": "Web"
        }, {
            "active": true,
            "defaultValue": false,
            "label": "Phone Inquiry",
            "validFor": null,
            "value": "Phone Inquiry"
        }, {
            "active": true,
            "defaultValue": false,
            "label": "Partner Referral",
            "validFor": null,
            "value": "Partner Referral"
        }, {
            "active": true,
            "defaultValue": false,
            "label": "Purchased List",
            "validFor": null,
            "value": "Purchased List"
        }, {
            "active": true,
            "defaultValue": false,
            "label": "Other",
            "validFor": null,
            "value": "Other"
        }],
        "precision": 0,
        "queryByDistance": false,
        "referenceTo": [],
        "relationshipName": null,
        "relationshipOrder": null,
        "restrictedDelete": false,
        "restrictedPicklist": false,
        "scale": 0,
        "soapType": "xsd:string",
        "sortable": true,
        "type": "picklist",
        "unique": false,
        "updateable": true,
        "writeRequiresMasterRead": false
    }



vickim1.396005552708281E12vickim1.396005552708281E12
Hi Abhinav,

Thats worked great, I seem to be getting alot of fields back though, is there a way to say only give me 1 fields options by passing the filds name?

also do you have the api link for this .

Thank you