I am using php soapclient to fetch data from Salesforce. I get a sObject back. I need to do field mapping, hence I need to convert this result into xml so that I can have a xslt to convert this data into the target structure. How can I convert the sobject to xml?


PHP is loosely TYPE langue. so you do not need XML to convert data into target structure.

See this example:

// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('../userAuth.php');
try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $query = 'SELECT Id,Name from Account limit 5';
  $response = $mySforceConnection->query(($query));

  foreach ($response->records as $record) {
} catch (Exception $e) {
  echo $e->faultstring;

Here you can $record object directly to access the properties and convert it into desired structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.