Right now I'm just learning the basics of PHP integration with the Partner WSDL, and plan to move on with the Enterprise WSDL later.

If you have a question, I'd do my best to answer. For now it seems that the blind leading the blind is what SFDC has to offer for PHP programmers. Numerous of the examples do not run, full of typos and obvious copies from enterprise <--> partner wsdl without adjusting the code, I'm patching these as I see them in the documentation.

What follows is my list of "Eureka" moments. Things which stopped me up for a while because there was no obvious solution in sight.



Okay, I'm running Debian Etch. I ran phpinfo and saw that the SOAP extension was included, so I figured it was also installed on the server. Bad assumption.

sudo apt-get install php-soap

...fixed a tremendous number of problems. I also read that you can install the php-pear SOAP client and include it in SforceBaseClient.php like so:

// require_once ('SOAP/client.php'); // uncomment to use SOAP from Pear
require_once ('SforceEmail.php');
require_once ('SforceProcessRequest.php');
require_once ('ProxySettings.php');
require_once ('SforceHeaderOptions.php');

Note that I commented it out. If you've got native SOAP support it's a lot faster, so I suggest you only use the Pear SOAPclient class in situations where you cannot enable native SOAP support.


To start with, wherever you see $PASSWORD it is actually $PASSWORD.$SECURITY_TOKEN. The security token can be generated by logging into SFDC and surfing to setup->My Personal Information->Reset My Security Token. This will result in an email to you containing a token.

WSDL: so many choices, so many chances for compatibility

At the same time you generate your first Security Token (above), hit setup->Develop->API and download your WSDL files. It is important to note that Enterprise WSDL files only work with your Organization, and that Partner WSDL files only work in the Developer or Organization context, because they contain a different login URL for each. So if you are Developing, use a WSDL from your Developer login. If you are Deploying, use a WSDL from your Organization login.

Using Partner WSDL, describe the fields of an sObject:

You've created a new "Merchandise" object and now you want to access it from your PHP scripts. The minimum requirement is to know the object and field names. There's no SELECT * FROM in "SOQL" (abuse cited) so we can't grab all the fields and observe them that way. There's a "describe" method, but it's (ahem) a bit verbose. Here's a tidy little snippet which will reveal the relevant field names:

foreach ($results as $result) $fields[$result->label]=$result->name;


    [Record ID] => Id
    [Owner ID] => OwnerId
    [Deleted] => IsDeleted
    [Merchandise Name] => Name
    [Created Date] => CreatedDate
    [Created By ID] => CreatedById
    [Last Modified Date] => LastModifiedDate
    [Last Modified By ID] => LastModifiedById
    [System Modstamp] => SystemModstamp
    [Description] => Description__c
    [Price] => Price__c
    [Total Inventory] => Total_Inventory__c

The [Merchandise Name] is the name displayed in SFDC's user interface. "Name" is what you need to use when you are passing a field name to a method. __c denotes a custom field.

It's a bit confusing, the "Merchandise Name" field feels like a custom field too. That took a while to figure out, and is the primary reason I wrote this snippet.