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
melhedgesmelhedges 

Problem with Create using PHP 5

Hi There,
I finally downloaded the new PHP 5 toolkit, and am able to get everything to work, except creating a new lead.  From what I can tell in test, the line which it is getting caught up in, is the $result line. Please see code below.
 
    $mySforceConnection = new SforcePartnerClient();
    $sforceSoapClient = $mySforceConnection->createConnection($wsdl);
    $mySforceConnection->setSessionHeader($sessionId);
    $mySforceConnection->setEndpoint($location);
    $servertime = $mySforceConnection->getServerTimestamp();
    $myUserInfo = $mySforceConnection->getUserInfo();
 
 $fieldstoinsert =  array('FirstName'=>'mel','LastName'=>'hedge','Title'=>'me','Company'=>'bc','Email'=>'mel@bc.com','Phone'=>'222','State'=>'TX','Country'=>'USA','Industry'=>'Tech','Status'=>'Suspect','Region__c'=>'central','LeadSource'=>'web site','Contact_Source__c'=>'web site','OwnerId'=>'00G30000000lXXX');  
 $sObj = new sObject();
 $sObj->fields = $fieldstoinsert;
 $sObj->type = 'Lead';
 $result = $mySforceConnection->create(array ($sObj));
Tran ManTran Man
This is a bug.  I will need to update the create method to handle sObjects.

In the meanwhile, use the following syntax:

Code:
  $createFields = array (
    'FirstName' => 'First',
    'LastName' => 'Last',
    'Company' => 'Test Co',
    'SICCode__c' => '9999',
  );
  $createResponse = $mySforceConnection->create('Lead', $createFields);
  print_r($createResponse);

 

ch9devch9dev
So is there a way to create multiple records at once? (nested array of fields?)

Code:
  $createFields = array (
    'FirstName' => 'First',
    'LastName' => 'Last',
    'Company' => 'Test Co',
    'SICCode__c' => '9999',
  );

  $createMultiFields[] = $createFields;

    $createFields = array (
    'FirstName' => 'First 2',
    'LastName' => 'Last 2',
    'Company' => 'Test Co 2',
    'SICCode__c' => '9998',
  );

  $createMultiFields[] = $createFields;

  $createResponse = $mySforceConnection->create('Lead', $createMultiFields);
  print_r($createResponse);

 

Something like returns:

Code:
(
    [errors] =>
    [id] => a0A300000011dlkEAA
    [success] => 1
)
Shouldn't it errors + success = 2 since I would have uploaded 2 records?
   
 

Tran ManTran Man
I just posted a new release (PHP 5 Toolkit 1.0.3) with a fix to allow Create to handle multiple SObjects.  The test class, SforcePartnerClientTest.ph, was also updated.

The way you would do this now is to pass the create method an array of SObjects like so:

Code:
      $createFields = array (
        'FirstName' => 'DELETE_ME',
        'LastName' => 'DELETE_ME',
        'MailingCity' => 'San Diego',
        'MailingState' => 'CA'
      );
      $sObject1 = new SObject();
      $sObject1->fields = $createFields;
      $sObject1->type = 'Contact';
      $createResponse = $this->mySforceConnection->create(array($sObject1));
Changes in version 1.0.3:
=========================
* Updated Create method to handle multiple records.
* Set the default encoding to UTF-8
* renamed constructor methods to __constructor