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 comment:

  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


Get Record Type Id from lightning component in standard new action override (getting any url parameter)

Hi , Here we have requirement to get record type id from lightning component when standard "New" action is overrided. To get...