Home Integration Connecting Salesforce using PHP

If you found the security token(through email) under ” Setup | My Personal Information | Reset My Security Token ” or “My Settings | Personal | Reset My Security Token.” then you can use that token to connect salesforce along with password.

If you dont find token then you need to add your IP Address under “Network Access” to connect salesforce.

<?php
define(“USERNAME”, “[email protected]”);
define(“PASSWORD”, “test123”);
//define(“SECURITY_TOKEN”, “salesforce security token”);

require_once (‘soapclient/SforcePartnerClient.php’);

$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection(“PartnerWSDL.xml”);
//$login = $mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN); //
$login = $mySforceConnection->login(USERNAME, PASSWORD); //Not required token because added IP address to access salesforce
//echo “<pre>”;print_r($login);

$userInfo = $mySforceConnection->getUserInfo();
//echo “<pre>”;print_r($userInfo);

$query = “SELECT Id, FirstName, LastName, Phone from Contact”;
$response = $mySforceConnection->query($query);

$table .= “<table border=1>”;
$table .= “<tr>
<th>Contact ID </th>
<th>First Name</th>
<th> Last Name </th>
<th>Phone </th>
</tr>”;
foreach ($response->records as $record)
{
$table .= ‘<tr>
<td style=”padding:5px”>’.$record->Id.'</td>
<td style=”padding:5px”>’.$record->fields->FirstName.'</td>
<td style=”padding:5px”>’.$record->fields->LastName.'</td>
<td style=”padding:5px”>’.$record->fields->Phone.'</td>
</tr>’;
}
$table .= “</table>”;

echo $table;
?>

You may also like

Leave a Comment