You need to sign in to do that
Don't have an account?
![chris38 chris38](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
PHP5 - update some records
I want to select some records in a table and then modify them.
The execution failed when i try to update(Id not specified).
I don't really understand how to specify TheId for updating.
Thanks for help !
Hereafter my code :
// select some records
$query = "select * from contact where LastName like 'R%'";
$queryOptions = new QueryOptions(300);
$queryResponse = $this->mySforceConnection->query($query, $queryOptions);
$this->assertNotNull($queryResponse);
// update the field FirstName to 'Barbara'
$updateFields = array ("ID" => $this->theId, "FirstName" => 'Barbara');
$updateResponse = $this->mySforceConnection->update('Contact', $updateFields);
chris
The execution failed when i try to update(Id not specified).
I don't really understand how to specify TheId for updating.
Thanks for help !
Hereafter my code :
// select some records
$query = "select * from contact where LastName like 'R%'";
$queryOptions = new QueryOptions(300);
$queryResponse = $this->mySforceConnection->query($query, $queryOptions);
$this->assertNotNull($queryResponse);
// update the field FirstName to 'Barbara'
$updateFields = array ("ID" => $this->theId, "FirstName" => 'Barbara');
$updateResponse = $this->mySforceConnection->update('Contact', $updateFields);
chris
The new way to update is by using SObjects:
$updateFields = array (
'Id' => $id,
'MailingCity' => 'New York',
'MailingState' => 'NY'
);
$sObject1 = new SObject();
$sObject1->fields = $updateFields;
$sObject1->type = 'Contact';
$updateResponse = $this->mySforceConnection->update(array ($sObject1));
Thanks for the sample.
The only thing that I can't understand is where the $id comes from.
I saw the toolkit samples. I saw how it works when a record is created, but not how to modify an existing record.
It seems that I can't call a SQL query using 'update'.Is it right ?
What is $id ? The value of a key data, or other thing ?
The process that I have to do is :
- select a record by a key value (ok, I know to do it)
- then update some fields in this record (how to refer to the selected record ?)
An other thing : It seems that i can't write a query like 'select * from Contact'. Shall i give the explicit list of used fields ?
I hope you can help me
Thanks
$id was defined elsewhere in my code which I didn't include. It represents the id of the Contact object. "Update" is done in the edit.php of the sample.
Our query language is SOQL. Read more about in our docs under API Calls/Sforce Object Query Language (SOQL). You need to explicitly name the fields you want to retrieve.
HTH
Message Edited by Tran Man on 04-19-2006 10:28 AM
Be sure to check out the AppExchange Explorer or the Eclipse plugin. Both give you the capability to browse your database schema and data which can be incredibly helpful.
Message Edited by Tran Man on 04-26-2006 04:30 PM