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
BobbinBobbin 

Help required for creating records via php toolkit 13.0

I will try this posting again (sorry, new to this):  I have used the example provided by the php toolkit and customised it to fit my client's current implementation as below:
 
Code:
<—
error_reporting(E_ALL);
ini_set("soap.wsdl_cache_enabled", "0");
define("SOAP_CLIENT_BASEDIR", "soapclient");
include_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
include_once("constants.php");

try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login(SF_USER, SF_PASS);

  $description = "Request for User Registration: \n\n"
            ."Company Name: \nTest Company\n\n"
            ."User Name: Ryan Cauchi-Mills\n\n"
            ."Email Address: ryan@intercityurgent.co.nz\n\n";

  $sObject = array(
                    'Origin'                    => 'MoBiz',
                    'RecordTypeId'              => '012200000004v5q',
                    'MoBiz_User_Last_Name__c'   => 'Cauchi-Mills',
                    'MoBizUserName__c'          => 'Ryan',
                    'Company_Name__c'           => 'Test Company',
                    'MoBiz_User_Id__c'          => 'useridformobiz',
                    'Type'                      => 'Mobiz',
                    'Subject'                   => 'MoBiz Registration Request',
                    'Description'               => $description
                );

  echo "**** Creating the following:\r\n";
  $createResponse = $mySforceConnection->create($sObject,'Case');

  $ids = array();
  foreach ($createResponse as $createResult) {
    print_r($createResult);
  }

} catch (Exception $e) {
  echo "Exception found:\r\n";
  echo $mySforceConnection->getLastRequest();
  echo print_r($e);
}

–>

The response I though is:

**** Creating the following:
Notice: Undefined property: stdClass::$result in /var/www/digiweb01/improved/include/soapclient/SforceBaseClient.php on line 399

Warning: Invalid argument supplied for foreach() in /var/www/digiweb01/improved/include/test.php on line 34

What have I done wrong??


 
ClaiborneClaiborne
Several things are wrong.

1. Need to define $sobject as an SObject. Use:

         $sObject = new SObject();

2. An SObject has an id, a type, and fields, which is the array you currently have as $sObject. So use:
 
        $sObject.type = 'Case';
        $sObject.fields = <the array you now have for $sObject>;

3. The create operation wants to operate on an array. So use:
       
        $createResponse = $mySforceConnection->create(array($sObject));

Hope this helps.



BobbinBobbin
The create function in the PHP toolkit requests two arguments: data in the form of a stdClass object and the table/category to affect changes too.
 
Thank you very much for your reply though, I was worried no-one was going to reply!  Perhaps you could give me a complete example of a method to create records, that would be VERY MUCH appreciated.
 
Cheers
 
Ryan
ClaiborneClaiborne
OK, in the code below "client" is a salesforce.com connection. It is a working example.

Code:
function create($client) {
    $account = new SObject();
    $account->type = 'Account';
    $account->fields = $this->makeFields();
    
    $result = $client->create(array($account));
    
    if ($result->success) {
        $id = $result->id;
        return id;
    }
    else {
        return null;
    }
}

function makeFields(){
    $fields = array(
        "Name"=>'The Claiborne Company',
        "BillingStreet" => '2838 Coliseum Street',
        "BillingCity" => 'New Orleans',
        "BillingState" => 'LA',
        "BillingPostalCode" => '70115-3307',
        "Phone" => stripslashes(htmlspecialchars(substr($this->phone, 0, 40),ENT_QUOTES)),
        "Fax" => stripslashes(htmlspecialchars(substr($this->fax, 0, 40),ENT_QUOTES)),
        "NumberofEmployees" => 1); 
     return $fields;                  
}