function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cthulhu4242Cthulhu4242 

accessing the Id of a lookup field as a string, not an object in php

Ok, this one is driving me a little nutty.

I have a custom object one field of which is a lookup to a Contact. I need to be able to insert an Id into this custom field.

Unfortunately, when I get the result from my query:
$query = "SELECT ContactId FROM SelfServiceUser WHERE Id = '$sfid'";
...
return $r->fields->ContactId;

what is returned is of data type Object when what I really want is data type String. When I echo the returned value to the screen, it's the correct id, but the data type is wrong. How do I get the Id as a string?

Any clues would be appreciated.
Cthulhu4242Cthulhu4242
In case anyone else is having this trouble, the magic answer is:

return (string)$r->fields->ContactId;
Tran ManTran Man
This is how I do it:

Code:
<—php
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login("username@domain.com", "changeme");

  $query = 'Select Id, ContactId from SelfServiceUser';
  $response = $mySforceConnection->query(($query));
  $queryResult = new QueryResult($response);

  foreach ($response->records as $record) {
    $sobject = new SObject($record);
    echo $sobject->fields->ContactId;
    echo "\r\n";
  }
} catch (Exception $e) {
  echo $e->faultstring;
}
–>