Tuesday, 28 April 2015

Force.com Toolkit for PHP ( Creating a contact into the salesforce using Force.com Toolkit)


The Force.com PHP Toolkit provides an easy-to-use wrapper for the Force.com Web Services SOAP API, presenting SOAP client implementations for both the enterprise and partner WSDLs.

Download php tool kit."https://github.com/developerforce/Force.com-Toolkit-for-PHP" into your machine.

To run php samples we need a server.

Xampp:It is a free open source cross-platfrom web server package.

1)install 'Xampp' server .(while installing i gave name "PHPXAMPP")
Download Xampp Server:https://www.apachefriends.org/download.html
 After install 

2)2)Suppose i installed in F drive 
 Go to: F:\PHPXAMPP\htdocs
 Create your own folder, name it as you own (balajiPhPforce).

3)Now create your first php program in xampp and name it as “welcome.php”:

<!DOCTYPE html>

echo "Welcome to php world!";

4)Now double click on “XAAMP CONTROL PANEL” on desktop and START “Apache”

5)Type localhost on your browser and press enter:
It will show the following:

6)Now type the following on browser:
Below screenshot shows PHP files created under folder “balajiPHPforce”

1)Coming to Salesforce.com example .First we have to copy "soapClient" folder from PHP Toolkit to our folder "balajiPhPforce" which is in "htdocs" folder.

Create a "PHP" with name "ContactrecordCreation.php" page by using snippets as shown below.
Creating a contact record into salesforce.com.


require_once ('soapclient/SforcePartnerClient.php');
require_once ('soapclient/SforceEnterpriseClient.php');
define("USERNAME", "username");
define("PASSWORD", "password");
$mySforceConnection = new SforcePartnerClient();
 if (isset($_SESSION['partnerSessionId'])) {
                    $location = $_SESSION['partnerLocation'];
                    $sessionId = $_SESSION['partnerSessionId'];


                    echo "Used session ID for partner<br/><br/>\n";
                } else {
                    $mySforceConnection->login(USERNAME, PASSWORD);

                    $_SESSION['partnerLocation'] = $mySforceConnection->getLocation();
                    $_SESSION['partnerSessionId'] = $mySforceConnection->getSessionId();

                    echo "Logged in with partner<br/><br/>\n";
 $records = array();
$records[0] = new SObject();
                $records[0]->fields = array(
'FirstName' => 'balaji',
                    'LastName' => 'malemarpuram',
                    'email' => 'mbalaji105@gmail.com',
                    'BirthDate' => '1988-05-25'
$records[0]->type = 'Contact';
$response = $mySforceConnection->create($records);
$ids = array();
                foreach ($response as $i => $result) {
                    echo ($result->success == 1) 
                            ? $records[$i]->fields["FirstName"]." "
                                .$records[$i]->fields["LastName"]." "
                                ." created with id ".$result->id."<br/>\n"
                            : "Error: ".$result->errors->message."<br/>\n";
                    array_push($ids, $result->id);

Run this file as explained above.

I referred the following references:



All the best.


  1. I am really impressed the way you have written the blog. Hope we are eagerly waiting for such post from your side. HATS OFF for the valuable information shared!
    PHP Training in Chennai
    PHP Training Chennai
    PHP Course in Chennai

  2. I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
    online Python training | python training in chennai | Python training course in Chennai

  3. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    excel advanced excel training in bangalore | Devops Training in Chennai


  4. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    AWS Interview Questions And Answers

    AWS Tutorial |Learn Amazon Web Services Tutorials |AWS Tutorial For Beginners

    AWS Online Training | Online AWS Certification Course - Gangboard

    AWS Training in Toronto| Amazon Web Services Training in Toronto, Canada

  5. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    automation anywhere online Training

    angularjs interview questions and answers


Convert 15 character IDs to 18 character IDs in formula field

Hi , We have new method " CASESAFEID() "in formula field now to make 15 character Id to 18 character. Classic 1. Go to  Se...