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
Mike @ PartnersMike @ Partners 

Update more then one lead at the same time

I am trying to update more then one lead at a time. I am pulling the lead ID numbers and then i need to update all the ID numbers with a cretin field. I have gotten the php5 toolkit to pull the ID no problem, and i can get it to update no problem. The problem is I can only get it to update one ID. And ideas on where I am going wrong?

 

Thank you for your help,

Mike

Tran ManTran Man
Can you post some code and any responses from your update?


Mike @ PartnersMike @ Partners
Here is my code for this project:

Code:
function dedupesender()
{
$senderIdl2 = getsenderleaddedupe();
$senderIdc2 = getsendercontactdedupe();
$Duplicate = 1;
global $mySforceConnection;
if (count($senderIdl2) + count($senderIdc2) > 1 ){
try {
$fieldsToupdate2
= array('ID'=>$senderIdl2, 'Duplicate_Lead__c' =>$Duplicate);
$sObject2 = new SObject();
$sObject2->fields = $fieldsToupdate2;
$sObject2->type = 'Lead';
$updateRespons2 = $mySforceConnection->update(array($sObject2));
var_dump($updateRespons2);
return $updateRespons2;
} catch (Exception $e) {
}
try {
$fieldsToupdate2
= array('ID'=>$senderIdc2, 'Duplicate_Contact__c' =>$Duplicate);
$sObject3 = new SObject();
$sObject3->fields = $fieldsToupdate2;
$sObject3->type = 'Contact';
$updateRespons2 = $mySforceConnection->update(array($sObject3));
var_dump($updateRespons2);
return $updateRespons2;
} catch (Exception $e) {
}
}
}


function getsendercontactdedupe() {
global $mySforceConnection;
$senderid1 = getsendercontactdedupeQ();
if (count($senderid1) > 0){
try {
foreach ($senderid1 as $r) {
$r = new SObject($r);
$senderIdc = $r->Id;
return $senderIdc;
}
} catch (Exception $e) {
}
}
else $senderIdc = "";
return $senderIdc;
}

function getsenderleaddedupe() {
global $mySforceConnection;
$senderid2 = getsenderleaddedupeQ();
if (count($senderid2) > 0){
try {
foreach ($senderid2 as $r) {
$r = new SObject($r);
$senderIdl = $r->Id;
return $senderIdl;
}
} catch (Exception $e) {
}
}
else $senderIdl = "";
return $senderIdl;
}

function getsendercontactdedupeQ() {
global $mySforceConnection;
$SenderEmail = $_GET['SenderEmail'];
$query = "SELECT Id from Contact where Contact.Email='$SenderEmail'";
$queryOptions = new QueryOptions(25);
$response = $mySforceConnection->query(($query), $queryOptions);
return $response->records;
}

function getsenderleaddedupeQ() {
global $mySforceConnection;
$SenderEmail = $_GET['SenderEmail'];
$query = "SELECT Id from Lead where Lead.Email='$SenderEmail'";
$queryOptions = new QueryOptions(25);
$response = $mySforceConnection->query(($query), $queryOptions);
return $response->records;
}

And here is what i get retuned for this code:

object(stdClass)#8 (3) { ["errors"]=> NULL ["id"]=> string(18) "00Q3000000CTc5OEAT" ["success"]=> bool(true) }

I dont get a error. The php toolkit doesnt have a proublem, but i need it to update all the IDs it pulls out. Right now it will only update one, and leave that other ID as if nothing happend.

Thank you foe your help,
mike

Tran ManTran Man
That's because you return as soon as you make one update.

Also try batching up the updates like this:

$updateRespons2 = $mySforceConnection->update(array($sobject2, $sObject3));

Another thing, you only need one try/catch statement to surround your update call.

Message Edited by Tran Man on 05-24-2006 05:41 PM