Tuesday, 28 April 2015

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

Hi,

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>
<html>
<body>

<?php
echo "Welcome to php world!";
?>  

</body>
</html>
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:
http://localhost/balajiPhPforce/
Below screenshot shows PHP files created under folder “balajiPHPforce”

Output:
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.
Code:
====
Creating a contact record into salesforce.com.

Eg:

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

                    $mySforceConnection->setEndpoint($location);
                    $mySforceConnection->setSessionHeader($sessionId);

                    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"]." "
                                .$records[$i]->fields["email"]
                                ." created with id ".$result->id."<br/>\n"
                            : "Error: ".$result->errors->message."<br/>\n";
                    array_push($ids, $result->id);
                }
?>

Run this file as explained above.

Output:
---------
I referred the following references:


https://developer.salesforce.com/page/Tksample.php
https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Toolkit_for_PHP

http://www.tutorialspoint.com/shorttutorials/run-a-php-program-in-xampp-server


All the best.

7 comments:

  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

    ReplyDelete
  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

    ReplyDelete

  3. 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

    ReplyDelete
  4. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    sap training in chennai

    sap training in tambaram

    azure training in chennai

    azure training in tambaram

    cyber security course in chennai

    cyber security course in tambaram

    ethical hacking course in chennai

    ethical hacking course in tambaram

    ReplyDelete

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...