A developer contacted me about integration between Salesforce.com & CodeIgniter PHP Framework. I thought that it would be better to post my response on my site due to anyone else may need the same thing.

Mukul,

I hope that I can answer this for you. You stated that you needed to create a new contact for a newly created user in salesforce.

To answer your question with a simple answer, yes you can do it.

In order to do it all you would basically need is the data from a source, such as a database or CSV file, that would have the information that you would need to create a new contact.

1. Download the PHPToolKit from the Menu on my home page. That is the main connection Class that you use to connect to Salesforce.com's API. There is a folder in the download called "soapclient". That is the folder that you will need

2. In order to create a new contact, you will need the ID from the User table of the newly created user in salesforce. The reason you need this is because you need to set the "OwnerId" of the new contact to that new user.

3. Here is an example script that will add a new contact to salesforce:

PHP Code:

<?php

/*****  Code Igniter code here .......... ******/

ini_set("soap.wsdl_cache_enabled","0");

//change the paths to match your server and script location
require_once ('./soapclient/SforcePartnerClient.php');
require_once (
'./soapclient/SforceHeaderOptions.php');

$mystuff = array('OwnerId'          => '00540000000wxjkAAA'// This is the owner id of the newely created User Id that you created in Salesforce
                 
'LastName'         => 'Wiley',
                 
'FirstName'        => 'heather',
                 
'Email'            => 'user@email.com'); // change this to a valid email
//clean User to allow changing of characters to XML
$mystuff array_map('htmlspecialchars',$mystuff);

//try to add User from from array
try
{
    
//salesforce login and wsdl - change the paths to match your server and script location
    
$wsdl './soapclient/partner.wsdl.xml';
    
$userName "user@email.com"// change this to a valid email
    
$password "password"// change this to a valid password

    //connect to salesforce
    
$client = new SforcePartnerClient();
    
$client->createConnection($wsdl);
    
$loginResult $client->login($userName,$password);

    
$sObject = new sObject();
    
$sObject->type 'Contact';
    
$sObject->fields $mystuff;


    
//this part adds the contact to salesforce
    
$result $client->create(array($sObject));

    if (
$result->success)
    {
        echo 
"New contact has been added to your instance of Salesforce with an Id of ".$result->id."<br />";
        echo 
"**************** ALL DONE ****************<br />";
        exit;
    }
    else
    {
        
$errMessage $result->errors->message;
        echo 
$errMessage;
    }

}
catch (
exception $e)
{
    
// This is reached if there is a major problem in the data or with
    // the salesforce.com connection. Normal data errors are caught by
    // salesforce.com
    
echo '<pre>'.print_r($e,true).'</pre>';
    return 
false;
    exit;
}


?>
4. you could add this to one of your CodeIgniter scripts anywhere and it would create the new contact.


I added this to my forum in case someone else may need to implement the same thing

Hope this helps, let me know if you have any other questions


~Mike


************************************************** ************************************************** *

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you're a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you're tired of ponderously large and thoroughly undocumented frameworks