Here is the example of php code which shows the Salesforce.com's API login inside the While loop:
PHP Code:
<?
while ($record_count == $number_records)
{
// Reset the php execution time to 20 seconds every time we get new
// records from the database
set_time_limit(20);
$sql = "SELECT id AS ownerid,
external_id as \"external_field__c\",
address as \"business address\"
FROM database_table
WHERE ROWCOUNT BETWEEN $starting_record AND ($starting_record + ($number_records-1))
ORDER BY ROWCOUNT";
$recordSet = $conn->Execute($sql);
$all_fields = array();
$i = 0;
while ($row = $recordSet->FetchRow())
{
$all_fields[$i]['OWNERID'] = $row['OWNERID'];
$all_fields[$i]['EXTERNAL_FIELD__C'] = htmlspecialchars(stripslashes(strip_tags($row['EXTERNAL_FIELD__C'])));
$all_fields[$i]['BILLINGADDRESS'] = htmlspecialchars($row['BILLINGADDRESS']);
// You can add addtional rows here if needed
$i++;
}
$record_count = $i;
$sObjects = array();
foreach ($all_fields as $fieldset)
{
$sObject = new sObject();
$sObject->type = 'Account';// Salesforce Table or object that you will perform the upsert on
$sObject->fields = $fieldset;
array_push($sObjects, $sObject);
}
//Move your Login information prior to sending your array to the
//function that will acutally perform the insert, update, or upsert
//This will insure that you always login each time you loop
//through the query that retrieves your data
// Salesforce Login information
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "myemail@email.com";
$password = "salesforce password";
// Process of logging on and getting a salesforce.com session
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
//This passes the client = the login to sales force
// the $sObjects = data to upsert
// $file_updated = accounts which are updated
// $file_created = accounts which are inserted
// $file_failed = accounts which failed
$success = account_team_insert($client, $sObjects);
// Update the overall counts
if (is_array($success))
{
$accounts_created = $accounts_created + $success[0];
$accounts_updated = $accounts_updated + $success[1];
$accounts_failed = $accounts_failed + $success[2];
}
$starting_record = $starting_record + $number_records;
}
?>
please note that this code will not work by copy and pasting into a script. Your organizational information, database connections, and other items need to be added/change/modified in order for this to work
Bookmarks