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”, “test@gmail.com”);
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;
?>

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

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

*