Reply
Regular Contributor
peterppt
Posts: 16
0
Accepted Solution

Using php Toolkit to add new record

 

I've used the toolkit for several applications to read data - but never to insert or update.  So I'm happy that the connection code and the WSDL are ok.

 

I'm trying to replicate the sample code PHP Toolkit 20.0 Upsert Sample (Enterprise) to insert a new contact record before tying something more adventurous !

 

<?php

define("USERNAME", "XXXXXXX");
define("PASSWORD", "YYYY");
define("SECURITY_TOKEN", "ZZZZZZZZZZZZZZZZZZZZ");



require_once ('soapclient/SforceEnterpriseClient.php');
require_once ('userAuth.php');

try {
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$sObject = new stdClass();

$sObject->FirstName = 'George';
$sObject->LastName = 'Smith';
$sObject->Phone = '512-555-555';
$sObject->BirthDate = '1927-01-25';
$sObject->Email = 'test@example.com';
	
$createResponse = $this->$mySforceConnection->create(array($sObject),'Contact');
echo "Creating new contact \r\n";
print_r($createResponse);	

} catch(Exception $e) {	
	echo $mySforceConnection->getLastRequest();
	echo $e->faultstring;
	
}

?>

 

The above code fails without any error message - presumably it fails to compile, although it passes my .php editor's checks.  I've changed the line 

 

$createResponse = $this->_$mySforceConnection->create(array($sObject),'Contact');

 

to

 

$createResponse = $this->$mySforceConnection->create(array($sObject),'Contact'); ( i.e removed the leading underscore ) because this gives a code error in my code checker.

 

Can anyone suggest what might be wrong with this code ?

 

Thanks.

Regular Contributor
Cheyne
Posts: 25
0

Re: Using php Toolkit to add new record

You shouldn't need $this in front of $mySforceConnection. Try using

$createResponse = $mySforceConnection>create(array($sObject),'Contact');

 

 

Cheyne Pierce
Salesforce.com Certified Developer
Regular Contributor
peterppt
Posts: 16
0

Re: Using php Toolkit to add new record

Brilliant - thanks very much.  I'm off to brush up my php OOP to work out why this-> was wrong !

 

Thanks again.

 

Peter

Regular Contributor
Svel
Posts: 14
0

Re: Using php Toolkit to add new record

HI,

You can find the Basic Tutorials about PHP and Salesforce Implementation using Below URL

http://theblogreaders.com/integration-between-salesforce-and-php


TheBlogreaders.com
Blog | Salesforce Certified Administrator | Salesforce Certified Developer

Regular Contributor
Svel
Posts: 14
0

Re: Using php Toolkit to add new record

HI,

You can find the Basic Tutorials about PHP and Salesforce Implementation using Below URL

http://theblogreaders.com/integration-between-salesforce-and-php


TheBlogreaders.com
Blog | Salesforce Certified Administrator | Salesforce Certified Developer