Obama '08

               
   

Go Back   Mike Simonds > Salesforce > Salesforce PHP Tutorials

This is a discussion on Salesforce Code Example #2 within the Salesforce PHP Tutorials forums, part of the Salesforce category; Here is the example of php code which shows the Salesforce.com's API

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 05-16-2007, 08:22 AM
Administrator
 
Join Date: May 2007
Posts: 248
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike
Salesforce Code Example #2

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



Powered by vBulletin


SEO by vBSEO 3.2.0 RC8 ©2008, Crawlability, Inc.

1 2 3 4 5