7

I have a simple custom contact object (with API name Contact__c) that I've created in my SalesForce DE site that has a single field (for testing connectivity) of Full_Name__c.

I am then trying to retrieve all of the contacts, specifically this field via PHP:

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient       = $mySforceConnection->createConnection(API_PATH . '/soapclient/partner.wsdl');
  $mylogin            = $mySforceConnection->login(API_USER, API_PASS . API_SECURITY_TOKEN);

  $query = 'SELECT C.Id, C.Full_Name__c
          FROM Contact__c C'; 
  $result = $mySforceConnection->query($query);
  $sObject = new SObject($result->records[0]);
  print_r($sObject);
} catch(Exception $e) {
  print_r($e);
}

I've downloaded the latest partner.wdsl (although as a partner WSDL, it is loosely typed and does not need to be downloaded with the creation/addition of custom objects and/or updated fields, correct?). I've verified that the user can connect and see the custom fields via the ForceExplorer. But when I run the above code, it connects but returns just the following:

SObject Object ( [type] => Contact__c [fields] => [Id] => a )

I am not getting any errors, invalid field error, etc, but for the life of me can't figure out why this isn't working.

I saw this example here, but it seems to be specific to Enterprise vs Partner, and the need to download the latest enterprise.wsdl every-time you change custom fields.

Any pointers?

2 Answers 2

4

Figured it out I believe, the problem related to how I was parsing the data that was being returned. Instead of feeding the returned data into an SObject, I am now just accessing it directly:

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient       = $mySforceConnection->createConnection(API_PATH . '/soapclient/partner.wsdl');
  $mylogin            = $mySforceConnection->login(API_USER, API_PASS . API_SECURITY_TOKEN);

  $query = 'SELECT C.Id, C.Full_Name__c
            FROM Contact__c C'; 
  $result = $mySforceConnection->query($query);

  for($i = 0; $i < count($result->records); $i++) {
    print_r($result->records[$i]->fields->Full_Name__c); 
  }
} catch(Exception $e) {
  print_r($e);
}
Sign up to request clarification or add additional context in comments.

2 Comments

I'm glad this helped you, but I don't think this is the answer. I am doing a print_r of result and my custom fields don't show. The WSDL is also updated. hmmm
ini_set('soap.wsdl_cache_enabled', '0'); JUST FIXED MY PROBLEM!
4
ini_set('soap.wsdl_cache_enabled', '0');

It does the trick.

2 Comments

It solves the problem of the old WSDL file (without all the new created/updated objects and fields) being cached by the system. Thanks to this, it forces the app to use the new updated WSDL file and thus allow to use new fields and objects since the last cached version.
Thank you!! I spent the last 2 hours trying to figure out why certain fields could be used in the WHERE condition but weren't showing in the results. This fixed it immediately. Adding to my standard code header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.