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.

define(“USERNAME”, “test@gmail.com”);
define(“PASSWORD”, “test123”);
//define(“SECURITY_TOKEN”, “salesforce security token”);

require_once (‘soapclient/SforcePartnerClient.php’);

$mySforceConnection = new SforcePartnerClient();
//$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>
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>
$table .= “</table>”;

echo $table;

Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *