Obama '08

               
   

Go Back   Mike Simonds > Salesforce > Salesforce PHP Tutorials

This is a discussion on PHP Salesforce and CodeIgniter Integration within the Salesforce PHP Tutorials forums, part of the Salesforce category; A developer contacted me about integration between Salesforce.com & CodeIgniter PHP Framework.

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 05-22-2008, 08:40 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
PHP Salesforce and CodeIgniter Integration

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

Reply

Tags
codeigniter, php integration, salesforce api

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