Salesforce

Getting a security token from your salesforce instance

To access Salesforce via a desktop application or other API-based application, you must replace your current password with a combination of your password and a security token:

1 Log in to Salesforce via the browser to request your security token.

2 Go to Setup -> My Personal Information -> Reset Security Token.

3 Click the Reset Security Token button to trigger an email which will contain your security token.

4 Select and copy the token from the email.

5 In the application, replace your password with combination of the password and the security token. For example, if your password is "MyPassword" and your security token is "XXXXXX", you would enter "MyPasswordXXXXXX" into the password field.

The security token will be sent to your email address (assuming you're the admin).

Getting started with the salesforce php api

from the url: http://www.mikesimonds.com/getting-started-php-salesforce-t117.html Credit goes to this site and this developer for being awesome.

Peter thanks for joining the site and I hope that I can help you, so let's give it a try:

1) You can use PHP with salesforce to perform almost any action you want with your projects. We currently use PHP to update, insert, and upset(salesforce function) to update all our data in salesforce for accounts, products, pricebooks and custom objects within salesforce. You can use PHP to create data or populate data from an object to a custom object using outbound messaging. You can use PHP to create a complete replication process of your data in Salesforce to a local database such as MySQL or Oracle. We do all these types of functions using PHP.

You will not be able to or would want to store your php scripts on a Salesforce server, they will all reside on your personal server or a company server. We have two servers, one for production and one for development that run Apache, PHP, and MySQL. The PHPToolkit is basically a group of scripts that are a class that is used to communicate with Salesforce's API.

The best way to get started is, and I am assuming that you have a windows PC, to download a free WAMP(windows apache web server for localhost development) and install it on your PC. You can do all the development on your local pc, that is what I do. I use XAMPP and since you are from Germany, here is the link > apache friends - xampp
Once you get that installed, follow the link from my main menu to the PHPToolKit and download it. There are some instructions and examples in the folder system within the zip file that will help you get started. I will also be glad to help you offline get setup

2) Once you have a webserver or localhost installed and have the toolkit installed, you can connect to Salesforce's API using your administrator Salesforce Account. If you want to have a development Salesforce account, which I would suggest, you can sign up for one for FREE > Force.com Developer Edition Sign-Up

The WSDL file can be downloaded right from wihin your Salesforce Account. Once you login to Salesforce, go to Setup > App Setup > Develop > API and you can generate a Partner WSDL file from there and then add that to your localhost or webserver and you can start development

I hope some of this makes sense, It seems like a lot, but it is not really. Let me know if you need any clarification and catch me on Skype anytime

Creating an event via the salesforce php api

Credit goes to this url for this post. I repost in case his site goes down and the info is lost. http://www.mikesimonds.com/adding-event-calendar-t111.html
The object to update or insert a new calendar event is the "Event" object in salesforce

There are 4 required fields that need to be inserted in order for the event to be added to your instance of Salesforce.

Assigned To
Subject
Start (date and time)
End (date and time)

Those API field names are

Owner Id
Subject
StartDateTime
EndDateTime

Remember that Salesforce times are all set to GMT, so you have to account for that. Since my time is set to -6 GMT, I have to adjust my code for that:

PHP Code:

<?php
ini_set("soap.wsdl_cache_enabled","0");


require_once ('./soapclient/SforcePartnerClient.php');
require_once ('./soapclient/SforceHeaderOptions.php');

$mystuff = array('OwnerId'          => '00550000000wI2LAAU', // Assigned To
                 'Subject'          => 'PHP Event Addidtion Test 2', //Subject
                 'StartDateTime'    => '2008-08-05T12:00:00.000Z', //Start time of event
                 'EndDateTime'      => '2008-08-05T13:00:00.000Z'); //End time of event **ALL TIMES ARE GMT, REMEMBER TO ACCOUNT FOR THIS****
//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
    $wsdl = './soapclient/partner.wsdl.xml';
    $userName = "me@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 = 'Event';
    $sObject->fields = $mystuff;


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

    if ($result->success)
    {
        echo "A new Calendar event 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;
}
?>