+ Start a Discussion
David_FBDavid_FB 

PHP: fieldsToNull with an array of field names - unexpected element

I'm having an issue with 'fieldsToNull' and PHP Toolkit 13. I can't pass through an array of field names without getting this error:

 

$sObject->fieldsToNull = array('Current_Projects__c', 'About_Me__c');

 

Unexpected element {http://www.w3.org/2001/XMLSchema}string during simple type deserialization

 

Though, if I do:

 

$sObject->fieldsToNull = 'Current_Projects__c';

 

This will work fine, and set the field to null. But doesn't solve my problem of being able to set multiple field values to null.

 

Has anyone encountered this issue before?

Message Edited by David_FB on 03-10-2009 04:45 AM
Best Answer chosen by Admin (Salesforce Developers) 
Park Walker (TAGL)Park Walker (TAGL)
I see the example you are trying is the Enterprise WSDL one. Is there a particular reason that you are using that? Are you using the Enterprise WSDL downloaded from the organization you are testing against?
 
This example uses the Partner WSDL. You'll need to add your path settings, but give it a try and see if it works for you:
 
try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $fields = array (
            'FirstName' => 'John',
            'LastName' => 'Smith',
            'Title' => 'President',
            'Phone' => '510-555-5555',
            'Company' => 'Bogus Records');
  $sObject = new sObject();
  $sObject->type = "Lead";
  $sObject->fields = $fields;
  $createResponse = $mySforceConnection->create(array($sObject));

  $leadid = $createResponse->id;

  $query = "select id, title, firstname, lastname, company from lead where id = '$leadid'";
  $queryResponse = $mySforceConnection->query($query);
  $queryResult = new QueryResult($queryResponse);
  echo "***** Initial query response *****\n";
  print_r($queryResult);

  $sObject = new SObject();
  $sObject->fieldsToNull = array ('Title', 'FirstName');
  $sObject->type = 'Lead';
  $sObject->Id = $leadid;
  $updateResponse = $mySforceConnection->update(array ($sObject));

  echo "***** Updated object with fields to null *****\n";
  print_r($updateResponse);

  $queryResponse = $mySforceConnection->query($query);
  $queryResult = new QueryResult($queryResponse);
  echo "***** Final query response *****\n";
  print_r($queryResult);

} catch (Exception $e) {
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}
 
Message Edited by Redsummit on 03-11-2009 09:14 AM

All Answers

David_FBDavid_FB
I should point out that $sObject is a stdobject
David_FBDavid_FB

I've also tried the sample shown here. I only changed the paths to the toolkit, and the username and password.

 

The object is created fine. Though on update, when trying to set fieldsToNull, I get the same error. Is there somewhere I can submit a bug?

Park Walker (TAGL)Park Walker (TAGL)
I see the example you are trying is the Enterprise WSDL one. Is there a particular reason that you are using that? Are you using the Enterprise WSDL downloaded from the organization you are testing against?
 
This example uses the Partner WSDL. You'll need to add your path settings, but give it a try and see if it works for you:
 
try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $fields = array (
            'FirstName' => 'John',
            'LastName' => 'Smith',
            'Title' => 'President',
            'Phone' => '510-555-5555',
            'Company' => 'Bogus Records');
  $sObject = new sObject();
  $sObject->type = "Lead";
  $sObject->fields = $fields;
  $createResponse = $mySforceConnection->create(array($sObject));

  $leadid = $createResponse->id;

  $query = "select id, title, firstname, lastname, company from lead where id = '$leadid'";
  $queryResponse = $mySforceConnection->query($query);
  $queryResult = new QueryResult($queryResponse);
  echo "***** Initial query response *****\n";
  print_r($queryResult);

  $sObject = new SObject();
  $sObject->fieldsToNull = array ('Title', 'FirstName');
  $sObject->type = 'Lead';
  $sObject->Id = $leadid;
  $updateResponse = $mySforceConnection->update(array ($sObject));

  echo "***** Updated object with fields to null *****\n";
  print_r($updateResponse);

  $queryResponse = $mySforceConnection->query($query);
  $queryResult = new QueryResult($queryResponse);
  echo "***** Final query response *****\n";
  print_r($queryResult);

} catch (Exception $e) {
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}
 
Message Edited by Redsummit on 03-11-2009 09:14 AM
This was selected as the best answer
David_FBDavid_FB

Thanks for your reply. Using the Partner client, it worked fine. Besides it working with the Partner client, are there any other reasons why I should use that over the Enterprise client?

 

Also, I guess that this means there is a bug with the Enterprise client and fieldsToNull?

Park Walker (TAGL)Park Walker (TAGL)
It really depends on what you are doing. If you work for a single company that has a stable Salesforce schema then there's not much to recommend the Partner client over the Enterprise client. The major problem with the Enterprise client is that people making changes to the schema can break your application. Since there is no easy way to retrieve the WSDL file dynamically you usually end up working with one that's out of date at some point.
 
That said, I've used the Enterprise client for years and only been bitten a few times, and I do find it easier to code than the partner client. As I started taking on more clients and wanted to reuse code it became clear that a switch to the Partner client made sense and I have developed some code to create 'real' objects from those that the Partner client uses.
 
Hope that helps.
 
Park
 
 
BTW, I did some testing of fieldsToNull using the Enterprise client and it does seem broken. The WSDL file indicates that it should be handled the same using either interface, but something in the client code appears to be causing the problem. 

SBgooSBgoo
Hello to everyone,

I know that this is an old thread, but our R&D found that the issue with fieldsToNull is still there: using Enterprise WSDL to set multiple fields to null in a CUSTOM OBJECT does not work.

As @david_FB stated we are not 'able to set multiple field values to null.'

This issue is still here, even after 6 years it was reported in this thread.
We also looked into SalesForce Known Issue but this is not documented at all. This surprised us.

We also opened a case #15150555 asking SalesForce to provide feedback about their awareness of the issue and an estimated time to deploy a fix.

This is quite surprising so maybe we are missing something and just need to be pointed in the right direction. 
For example, if Partner WSDL allowed to manage and set to null multiple fields on custom objects, then maybe we should just use it (in case they are included in the Enterprise license we have).

This thread will be referenced within the case so that SalesForce support can be updated about this. We hope that this time spent to provide precious information that allow SalesForce to improve as a product is used properly to improve.

Thanks for anyone providing feedback here.