user3147676
user3147676

Reputation: 93

PHP SoapClient dropping fields?

I'm using the php soap client functionality to invoke a call into Salesforce….and running into something weird that I can’ t figure out. It seems a field is getting dropped within the PHP call...I can see it in the getLastReponse, but its not passed along into the object from the query() call. I don't believe this is an issue with Salesforce or the wsdl at all.

The query passed into Salesforce:

$xml_array_query[‘query’]=“select Id, LastName, FirstName, Username, LMS_ID__c,
UserRole.Name, Name from User where IsActive=true and Name like '%Bunting%'”;

Invoke the client (assume already authenticated ok)

$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions, 'location' => $serverurl));
$header = new SoapHeader('urn:enterprise.soap.sforce.com', 'SessionHeader', array ('sessionId'=>$sessionid));
$client->__setSoapHeaders($header);
$response = $client->query($xml_array_query['query']);

Then output the last response (formatting out the XML for viewing purposes):

echo 'Last response: '. $client->__getLastResponse()."\n";

Last response: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<soapenv:Header>
<LimitInfoHeader>
<limitInfo>
    <current>43227</current>
    <limit>895000</limit>
    <type>API REQUESTS</type>
</limitInfo>
</LimitInfoHeader>
</soapenv:Header>
<soapenv:Body>
<queryResponse>
<result> 
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xsi:type="sf:User">
  <sf:Id>005d0x</sf:Id>
  <sf:FirstName>Susie</sf:FirstName>
  <sf:LMS_ID__c>BuntingSusieCC</sf:LMS_ID__c>    <------- KEY FIELD!
  <sf:LastName>Bunting</sf:LastName>
  <sf:Name>Susie Bunting</sf:Name>
  <sf:UserRole xsi:type="sf:UserRole">
     <sf:Id xsi:nil="true"/>
     <sf:Name>Agent Role</sf:Name>
  </sf:UserRole>
  <sf:Username>susie.bunting</sf:Username>
</records>
<size>1</size>
</result>
</queryResponse>
</soapenv:Body>
</soapenv:Envelope>

So, I know the query returned the LMS_ID__c field from the server...

But it doesn't look like the field and value are getting passed into the object...

var_dump($response);

object(stdClass)#6 (1) {
  ["result"]=>
  object(stdClass)#7 (4) {
    ["done"]=>
    bool(true)
    ["queryLocator"]=>
    NULL
    ["records"]=>
    array(2) {
      [0]=>
       object(stdClass)#8 (6) {
        ["Id"]=>
        string(18) "005d0x"
        ["FirstName"]=>
        string(6) "Susie"
        ["LastName"]=>
        string(7) "Bunting"
        ["Name"]=>
        string(14) "Susie Bunting"
        ["UserRole"]=>
         object(stdClass)#9 (2) {
          ["Id"]=>
          NULL
          ["Name"]=>
          string(18) "Agent Role"
        }
        ["Username"]=>
        string(27) "susie.bunting"
      }
    }
    ["size"]=>
    int(1)
  }
}

Where does the LMS_ID_c field go??? Its in the getLastReponse output, but when viewing the object from the query(), its not there.

It was my understanding that the soapclient would parse the XML to create the object and elements, is that not true?
Is this some quirk because of the underscores in the field name, and the instance of a double-underscore? I wouldn't think so, but I can't figured this out.

Any help appreciated...

Upvotes: 2

Views: 1060

Answers (1)

user3147676
user3147676

Reputation: 93

Turns out the issue was with the caching of the wsdl file apparently. I added this to the head of my script, and resolve the issue:

ini_set('soap.wsdl_cache_enabled',0);

Upvotes: 4

Related Questions