Fred the Man Fred the Man - 4 months ago 26
PHP Question

salesforce record object to string

I am trying to parse this object saleforce returns, however having no luck since it is not a String and I do not know how to make it a String.

Current code for the query:

<?php
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 DataIncluded__c from GMC_Contract__c limit 5';
$response = $mySforceConnection->query(($query));
foreach ($response->records as $record) {
print_r($record);
print_r("<br>");
}
} catch (Exception $e) {
echo $e->faultstring;
}
?>


Here when printed/run returns something like this:

stdClass Object ( [Id] => [DataIncluded__c] => 8 )
stdClass Object ( [Id] => [DataIncluded__c] => 11 )
stdClass Object ( [Id] => [DataIncluded__c] => 5 )


Assuming 3 records. I would like just to get the numbers instead, so it prints 8 then 11 then 5.

However substring does not work, and my attempts to change into a string have not worked. Any suggestion on how I could do this?

Answer

try this code

echo $record->DataIncluded__c

instead of

print_r($record)

because $record is an object and Id is an array.