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
peterpptpeterppt 

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.

Best Answer chosen by Admin (Salesforce Developers) 
CheyneCheyne

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

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

 

 

All Answers

CheyneCheyne

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

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

 

 

This was selected as the best answer
peterpptpeterppt

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

 

Thanks again.

 

Peter

SAKTHIVEL MSAKTHIVEL M

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

SAKTHIVEL MSAKTHIVEL M

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

Anil JinwalAnil Jinwal
how to retrieve data which was inserted by us .