+ Start a Discussion

Help : I need using DescribeSObjectResult - php example

I am trying to get picklist values (and modify them ) in the PHP API.
I can only find examples in Java and .NET.
I don't mind converting the examples to PHP , but I get stuck at the point of creating the object .

The object's class definition is not in the SS include files!
DescribeSObjectResult is only mentioned in the wsdl file .
How does this work? is the object created remotely?

I will really appreciate a PHP sample!



Tran ManTran Man
Have you tried this


Message Edited by Tran Man on 11-13-2007 09:29 AM

Hi Nick .
thank you but the link is broken.
 please put in the correct link.


This is a small function that I use to create a html picklist for specific field for a salesforce.com object.

$client is a active salesforce.com client, $objectType is the API name for the object (i.e., Account, Contact, etc.) $fieldName is the API name for the field with the picklist (i.e. Picklist__c, etc.), and $selected is the current value of the field (if known).

Hope this helps.


        // Creates an HTML Select list for a salesforce.com object
    function SelectList ($client, $objectType, $fieldName, $selected = null) {
        $result = $client->describeSObject($objectType);
        foreach ($result->fields as $field) {
            if ($field->name == $fieldName) {
                $selectString = "\n\t<select ".$width." name=\"".$fieldName."\">"; 
                foreach ($field->picklistValues as $value) {
                    $select = ($value->label == $selected) — "selected ":"";
                    $value = htmlspecialchars($value->label);
                    $selectString .= "\n\t\t<option ".$select." value=\"".$value."\">".$value."</option>";
                $selectString .= "\n\t</select>";   
        return $selectString;    


Tran ManTran Man
Sorry about that, the discussion board reformatted the URL with an emoticon.
This code works well for me:

    function describeSObject($sObjectType){
        $param = array('sObjectType' => $sObjectType);
        $this->result = $this->client->call('describeSObject', array('parameters' => $param), '', '', false, true);
        return $this->result['result'];

I can post additional code if you want the whole script for login, etc. But that should get you what you want as far as describing an object. It works well - retruns an array with every possible field and subfield. Prevents you from having to login to the client's account, or worse, have them describe their custom fields to you.