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
SieGeL2k9SieGeL2k9 

Retrieving LeadHistory via PHP Toolkit 13.0 - fields Oldvalue/Newvalue missing ???

Hi everbody,

I'm currently developing a synchronisation script with the PHP Toolkit 13.0 do have all major data from Salesforce available in our local Oracle Database.

So far everything works, however today I've tried to sync the "LeadHistory" object from Salesforce. This object contains two fields "oldvalue" and "newvalue", both are defined as "xs:anyType" in the WDSL file.

 

As long as there is no content in these fields the PHP API returns them as empty fields, which is correct behavour.

 

However as soon as there is any content available in these fields, the "$queryResult->records as $record" call did not contain these fields anymore? I was not able to find them in the result set returned from the API. The dataloader 15 exports these fields without problems.

 

I've checked the record where the oldvalue/newvalue fields are missing, and in the Dataloader output it is clearly shown that there is content in these fields.

 

Here is the code snippet to retrieve the data:

 

$response = $sforce->query("SELECT Id,IsDeleted,LeadId,CreatedById,CreatedDate,Field,OldValue,NewValue FROM LEADHISTORY");
$queryResult = new QueryResult($response);
if ($queryResult->size > 0) {

  foreach($queryResult->records as $record) {

      // Here the code extracts the data from $record->fields. And here are also the fields missing as soon as they contain data

   } 

}

 

If anyone has any idea how to solve this I would be glad to hear from you. For now I have to skip the LeadHistory object as the necessary informations are not available anyway. IMO the oldvalue/newvalue fields are used in the Leadhistory object whenever a Lead status change is performed, and these infos are of course necessary to have a real history available.

 

 

sinsiterrulezsinsiterrulez

Hi,

Even I have faced the same problem but when I tried to put the NewValue/OldValue data in other object...

What I found was these fields have data type as Object and NOT string. So if you write (string)response.OldValue then it might probably solve your problem..

 

 

SieGeL2k9SieGeL2k9

I sinsiterrulez,

 

thanks for your reply. However I've tested it again, now with the updated PHP Toolkit 13.1, but still I'm not able to access the oldvalue/newvalue fields. Strange enough both fields are missing whenever I get a record with field = 'status', for field='created' both fields exists??

I'm a little bit confused now, here the's code I'm using for tests:

 

 

$query = 'SELECT Id,IsDeleted,LeadId,CreatedById,CreatedDate,Field,OldValue,NewValue FROM LEADHISTORY WHERE LeadId=\'00Q20000004fhfbEAA\'';
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);

foreach ($queryResult->records as $record)
{
echo(str_repeat('-',80)."\n");
printf("ID=%s | Field=%s | OLD=%s\n",$record->Id, $record->fields->Field,$record->fields->OldValue);
if(isset($record->fields->OldValue)==false)
{
var_dump($record);
var_dump($queryResult);
exit;
}
}

 

So nothing special here. I would expect to find the OldValue/NewValue fields being accessable via $record->fields->OldValue, however as I've written, these fields simply does not exist in the resulting class object!

 

Here's an example how it looks for a "valid" (aka complete) record:

 

object(SObject)#9 (3) {
["type"]=>
string(11) "LeadHistory"
["fields"]=>
object(stdClass)#15 (7) {
["IsDeleted"]=>
string(5) "false"
["LeadId"]=>
string(18) "00Q20000004fhfbEAA"
["CreatedById"]=>
string(18) "00520000000rTndAAE"
["CreatedDate"]=>
string(24) "2007-11-06T10:46:05.000Z"
["Field"]=>
string(7) "created"
["OldValue"]=>
string(0) ""
["NewValue"]=>
string(0) ""
}
["Id"]=>
string(18) "0172000000BB3h0AAD"
}

 

So the fields "OldValue" and "NewValue" are clearly shown. Now, from the same query, the incomplete object:

 

object(SObject)#18 (3) {
["type"]=>
string(11) "LeadHistory"
["fields"]=>
object(stdClass)#19 (5) {
["IsDeleted"]=>
string(5) "false"
["LeadId"]=>
string(18) "00Q20000004fhfbEAA"
["CreatedById"]=>
string(18) "00520000000rTniAAE"
["CreatedDate"]=>
string(24) "2009-07-24T13:50:00.000Z"
["Field"]=>
string(6) "Status"
}
["Id"]=>
string(18) "0172000001M7cylAAB"
}

 

 Maybe I'm doing something wrong here, but from what I see everything works. Only the "*History" tables seems to be a problem...so how can you access these fields if they are not existing in the result?

BTW: This test is running on PHP 5.3.1RC1, I've tested it both with PHP 5.2.11 and 5.3.1RC1, the results are the same.

 

If you have managed it to get your hands on these fields I would really appreciate it if you could paste some code snippet how you access these fields.

 

 

Igor GolikovIgor Golikov

I tried PHP toolkit 20.0  SforcePartnerClient  with same result.

 

But SforceEnterpriseClient  works well!

 

JustinCJustinC

Same problem here, using PHP Toolkit 20.0 and SforcePartnerClient, NewValue and OldValue doesn't seem to be exist in the results that are returned using a query like:

 

SELECT Id,LeadId,CreatedById,CreatedDate,Field,OldValue,NewValue from LeadHistory WHERE ID='<ID>' AND Field='Status'

 

Anyone had any luck on this?

Igor GolikovIgor Golikov

Try SforceEnterpriseClient