I'm writing a form on a website that submits data to the opportunities object of a SF install. This works but there are picklists in the opportunities object that ideally I want to be replicated directly into the source form on the external website. Ie, when this form loads it talks to SF and obtains the picklist content and writes select lists with the same exact values, therefore avoiding mismatches between the data.

I've concluded the only way that I can see this can be done is with the describeSObject fuction. So I have


This seems to work but returns a huge amount of data. Is there a quick way to iterate over this huge returned dataset or to just filter down to the field I want in the first place ?

Any suggestions most welcome.

1 Answer 1


I found an answer and thought it useful to document here. In short, its thanks to stephanbit and their post on the salesforce forums.

Based on his code I have...

function SelectList ($client, $objectType, $fieldName, $selected = null) {
    $result = $client->describeSObject($objectType);
    foreach ($result->fields as $field) {
        if ($field->name == $fieldName) {
            $selectString = "";
            foreach ($field->picklistValues as $value) {
                $select = ($value->label == $selected) ? ' selected="selected" ':'';
                $value = htmlspecialchars($value->label);
                $selectString .= "\n\t\t<option ".$select." value=\"".$value."\">".$value."</option>";
    return utf8_decode($selectString);    

I then use it in the html form as follows

<select id="customID" name="customName">
echo SelectList($mySforceConnection, 'Opportunity', 'Field__c');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .