function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
I am getting an invalid sobject error...why
$query = "SELECT Id from Account"; $queryResult = $mySforceConnection->query($query); $records = $queryResult->records; foreach ($records as $record) { $sObject = new SObject($record); echo "Id = ".$sObject->Id; echo "First Name = ".$sObject->fields->FirstName; echo "Last Name = ".$sObject->fields->LastName; } $contact = new SObject('Account', null, array( 'Id' => "33234534534", 'Name' => "name" ) ); $createResult = $mySforceConnection->create($contact); //$query = "INSERT INTO `Account` (`Id`) VALUES (`345345345345345345443543`)"; //$queryResult = $mySforceConnection->query($query); if($createResult) { echo "You have successfully replied<br>"; } else { echo "There is some problem in replying<br>"; }
The object ID is returned by the create call. There is nothing similar to the SQL method of obtaining the ID.
The return value of a query returns an array of sObjects; you do not need, nor should you try, to create new ones.
You may want to take a look at the PHP Toolkit and it's documentation here.
I believe that this will help with your immediate question:
<?php
// note that these path setting probably do not match yours
define('SOAP_CLIENT_BASEDIR', './soapclient');
$path = '/Library/WebServer/Documents/phptoolkit/soapclient';
ini_set('include_path',ini_get('include_path').':'.$path);
require_once ('SforcePartnerClient.php');
require_once ('SforceHeaderOptions.php');
require_once ('userAuth.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection($path.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$fields = array (
'Name' => 'Bogus Records',
'BillingCity' => 'Nashville',
'BillingState' => 'TN',
'Phone' => '510-555-5555');
$sObject = new SObject();
$sObject->fields = $fields;
$sObject->type ='Account';
$createResponse = $mySforceConnection->create(array($sObject));
$AccountId = $createResponse->id;
print_r($createResponse);
'FirstName' => 'John',
'LastName' => 'Smith',
'Phone' => '510-555-5555',
'AccountId' => $AccountId);
$sObject2 = new SObject();
$sObject2->fields = $fields;
$sObject2->type = 'Contact';
$createResponse = $mySforceConnection->create(array($sObject2));
$ContactId = $createResponse->id;
$query = "Select c.LastName, c.Id, c.FirstName, c.Account.BillingState,
c.Account.BillingCity, c.Account.Name, c.Account.Id
From Contact c
Where c.Account.Name = 'Bogus Records'";
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);
print_r($queryResult);
} catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;
}
?>
I am getting an invalid sobject error...why
$query = "SELECT Id from Account";
$queryResult = $mySforceConnection->query($query);
$records = $queryResult->records;
foreach ($records as $record) {
$sObject = new SObject($record);
echo "Id = ".$sObject->Id;
echo "First Name = ".$sObject->fields->FirstName;
echo "Last Name = ".$sObject->fields->LastName;
}
$contact = new SObject('Account',
null,
array(
'Id' => "33234534534",
'Name' => "name"
)
);
$createResult = $mySforceConnection->create($contact);
//$query = "INSERT INTO `Account` (`Id`) VALUES (`345345345345345345443543`)";
//$queryResult = $mySforceConnection->query($query);
if($createResult)
{
echo "You have successfully replied<br>";
}
else
{
echo "There is some problem in replying<br>";
}
The object ID is returned by the create call. There is nothing similar to the SQL method of obtaining the ID.
The return value of a query returns an array of sObjects; you do not need, nor should you try, to create new ones.
You may want to take a look at the PHP Toolkit and it's documentation here.
I believe that this will help with your immediate question:
<?php
// note that these path setting probably do not match yours
define('SOAP_CLIENT_BASEDIR', './soapclient');
$path = '/Library/WebServer/Documents/phptoolkit/soapclient';
ini_set('include_path',ini_get('include_path').':'.$path);
require_once ('SforcePartnerClient.php');
require_once ('SforceHeaderOptions.php');
require_once ('userAuth.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection($path.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$fields = array (
'Name' => 'Bogus Records',
'BillingCity' => 'Nashville',
'BillingState' => 'TN',
'Phone' => '510-555-5555');
$sObject = new SObject();
$sObject->fields = $fields;
$sObject->type ='Account';
$createResponse = $mySforceConnection->create(array($sObject));
$AccountId = $createResponse->id;
print_r($createResponse);
$fields = array (
'FirstName' => 'John',
'LastName' => 'Smith',
'Phone' => '510-555-5555',
'AccountId' => $AccountId);
$sObject2 = new SObject();
$sObject2->fields = $fields;
$sObject2->type = 'Contact';
$createResponse = $mySforceConnection->create(array($sObject2));
$ContactId = $createResponse->id;
print_r($createResponse);
$query = "Select c.LastName, c.Id, c.FirstName, c.Account.BillingState,
c.Account.BillingCity, c.Account.Name, c.Account.Id
From Contact c
Where c.Account.Name = 'Bogus Records'";
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);
print_r($queryResult);
} catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;
}
?>