You need to sign in to do that
Don't have an account?
Jordan Lev
Inserting/Updating multiple records
Does anyone know how to call update() for more than one object at a time (using WebService_sforceService_Soal.php)? Here is the code I have for updating one record:
$client = new SalesforceClient($SESSION);
$client->_endpoint = $_COOKIE['sf_endpoint'];
$myFields = array('type'=>'lead', 'Id'=>'00S20000007k888AAA', 'Company'=>'testCo');
$result = $client->update($myFields);
This code works perfectly, but I cannot figure out how to pass more than one "sObject" (php array) to it. My first guess was to make $myFields an array of arrays, but that didn't work. Then I tried just adding more and more key/value pairs to the $myFields array ('type'=>'lead', 'Id'=>'00S20000007k888AAA', 'Company'=>'testCo1', 'type'=>'lead', 'Id'=>'00S20000007k9999BB', 'Company'=>'testCo2', etc. etc.) but that didn't work either.
Thanks for any help you can provide (I really don't want to make multiple calls to the update function).
-Jordan Lev
$client = new SalesforceClient($SESSION);
$client->_endpoint = $_COOKIE['sf_endpoint'];
$myFields = array('type'=>'lead', 'Id'=>'00S20000007k888AAA', 'Company'=>'testCo');
$result = $client->update($myFields);
This code works perfectly, but I cannot figure out how to pass more than one "sObject" (php array) to it. My first guess was to make $myFields an array of arrays, but that didn't work. Then I tried just adding more and more key/value pairs to the $myFields array ('type'=>'lead', 'Id'=>'00S20000007k888AAA', 'Company'=>'testCo1', 'type'=>'lead', 'Id'=>'00S20000007k9999BB', 'Company'=>'testCo2', etc. etc.) but that didn't work either.
Thanks for any help you can provide (I really don't want to make multiple calls to the update function).
-Jordan Lev
1) You need to alter the WebService_SforceService_Soap.php file's functions (in this example I use the create() function but the same process applies to update() and delete() as well). Change it from:
function &update($sObjects) {
$update =& new SOAP_Value('{urn:partner.soap.sforce.com}update', false, $v=array("sObjects"=>$sObjects));
return $this->call("update",
$v = array('update'=>$update),
array('namespace'=>'urn:partner.soap.sforce.com',
'soapaction'=>'',
'style'=>'document',
'use'=>'literal' ));
}
to:
function &update($sObjects) {
$updates =& new SOAP_Value('{urn:partner.soap.sforce.com}update', false, $v=$sObjects);
return $this->call("update",
$v = $updates,
array('namespace'=>'urn:partner.soap.sforce.com',
'soapaction'=>'',
'style'=>'document',
'use'=>'literal' ));
}
~Note how we simply take out the 'array()' function in both the 'new SOAP_Value' and the '$this->call' call. This function was expecting one array (one sObject), and subsequentally turning that one sObject into an array of the one sObject. But we want to be able to pass an array of arrays (array of sObjects) to this function, so we don't want to wind up with an array of arrays of arrays (got that?).
~Note that I also changed the name of the '$update' variable to '$updates', because I'm **bleep**.
2) When you call the update() function in your code, you need to pass it arrays of sObjects. Similarly, when retrieving error messages, you need to remember that the $result will be an array of sObjects. So my code now looks like this:
$client = new SalesforceClient($SESSION);
$client->_endpoint = $_COOKIE['sf_endpoint'];
$myLeads = array();
$sObject = array('type'=>'lead', 'Id'=>'00X20000007q123456', 'Company'=>'test Co.');
$myLeads[] = $sObject;
$sObject = array('type'=>'lead', 'Id'=>'00X20000007qABCDEF', 'Company'=>'test Inc.');
$myLeads[] = $sObject;
//etc. etc...
$result = $client->update($myLeads);
foreach($result as $val) {
if ($val->success == "true") {
echo "SUCCESS! ID: " . $val->id . "<br />\n";
} else {
echo "FAILURE: " . $val->errors->message . "<br />\n";
}
}
~The sample code that comes with the wrapper shows an example like this:
$FIELDS = array('type'=>'lead','FirstName'=>'newtest','LastName'=>'test','Company'=>'testthis');
$client->create($FIELDS);
If you have already changed your create() function in WebService_SforceService_Soap.php (see step 1 above), then you would need to do something like this to get the sample code to work:
$sObjects = array(array('type'=>'lead','FirstName'=>'newtest','LastName'=>'test','Company'=>'testthis'));
$client->create($sObjects);
**Question to adamg: Is this going to adversely affect functionality? I kept that $v=$sObjects thing in there, although I can't see what the $v is for (perhaps some other module uses it for displaying errors?). Let me know if this is all "kosher".
Hope this helps (and thanks so much to the people who wrote these php wrappers in the first place -- you rock!)
-Jordan Lev
Hi Jordan,
just stumbled over the same problem and then found your fix here. Tried it and it works like a charm!
Thank you! :-)
Cheers,
Harald
(Just wish I could've found this sooner!)
any help greatly appreciated
aj
Thanks!
-Charlie
http://forums.sforce.com/sforce/board/message?board.id=PerlDevelopment&message.id=604
Thanks!