You can't set the ID when you're doing an insert -- ID is an autogenerated field. In general you should wrap your stuff here in a try/catch as with this sample:
Look at what's getting stored in $createResult. Try print_r on it perhaps. You'll see that it contains an array of SaveResults, and each one will have an ID attribute. In your case there will be just one, but it will contain the ID of the newly created object.
Ok, well, run a debugger on it or print_r your $createResult variable to look at its contents. That was just off the top of my head -- maybe PHP makes it not an array if it's just got one element. I speak many languages, I tend to get them confused.
Object id #9stdClass Object
( [errors] => stdClass Object ( [fields] => Name [message] =>
Unable to create/update fields: Name. Please check the security
settings of this field and verify that it is read/write for your profile
All Answers
Thank you for your reply Simon, can you provide examples...
I've tried using create on an sObject and it fails?
$contact = new SObject('Account',
null,
array(
'Id' => "33234534534",
'Name' => "name"
)
);
$createResult = $mySforceConnection->create($contact);
You can't set the ID when you're doing an insert -- ID is an autogenerated field. In general you should wrap your stuff here in a try/catch as with this sample:
http://wiki.apexdevnet.com/index.php/PHP_Toolkit_13.0_Update_Sample_(Partner)
That way it will actually tell you what the error is.
Ah that was good thinking werewolf...
ok I think its inserting stuff into the database now... how do pull out the LAST INSERTED / UPDATED id
Hey ya buddy,
just tried that
Ok I know I can run a select after the insert... and pull out what should be the last id, from an order by date DESC query...
but is there a function to pull out the last id.
Yo, ok
I am making a web form, which would allow a client to add a person to the account table.
I then need the id of this new person to pass into a new web form. A claims form.
Thus I need the id of the account to attach to a new claim.
I was not sure how to do this so in apex and java - from what I could tell that would just create the forms based on the api.
So yeah... now I've managed to make a new insert... is there a neat way of getting the latest id like
$last_id = mysql_insert_id();
Well, as I said, it's going to be in your SaveResult object. Off the top of my head it would probably be something like $createResult[0]->Id.
hey ok
so how I do retrieve it as a variable?
$createResult = $mySforceConnection->create($sObjects_insert);
is it something like
$lastid->id-> $createResult;
oo
Fatal error: Cannot use object of type stdClass as array
Hey ya guys,
one more hurdle.
oK I've got the last id thing.
now I want to insert it into the contact form just as a tester
I get an error
$sObject = new sObject();
$sObject->type = 'Contact';
$sObject->fields = array('Name' => $fullname, 'AccountId' => $accountid);
array_push($sObjects_insert, $sObject);
echo "insert<br />";
flush();
if (count($sObjects_insert) > 0)
{
$createResult = $mySforceConnection->create($sObjects_insert);
echo''.$createResult.'';
print_r($createResult);
}
Object id #9stdClass Object ( [errors] => stdClass Object ( [fields] => Name [message] => Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile