PHP code example of chorton / salesforce-api-php-wrapper
1. Go to this page and download the library: Download chorton/salesforce-api-php-wrapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chorton / salesforce-api-php-wrapper example snippets
$sfClient = \Crunch\Salesforce\Client::create('https://test.salesforce.com/', 'clientid', 'clientsecret');
$tokenGenerator = new \Crunch\Salesforce\AccessTokenGenerator();
$accessToken = $tokenGenerator->createFromJson($_SESSION['accessToken']);
$sfClient->setAccessToken($accessToken);
$results = $sfClient->search('SELECT Name, Email FROM Lead Limit 10');
print_r($results);
class SalesforceConfig implements \Crunch\Salesforce\ClientConfigInterface {
/**
* @return string
*/
public function getLoginUrl()
{
return 'https://test.salesforce.com/';
}
/**
* @return string
*/
public function getClientId()
{
return 'clientid';
}
/**
* @return string
*/
public function getClientSecret()
{
return 'clientsecret';
}
/**
* Version of the API you wish to use
* @return string
*/
public function getVersion()
{
return 'v37.0';
}
}
$sfConfig = new SalesforceConfig();
$sfClient = new \Crunch\Salesforce\Client($sfConfig, new GuzzleHttp\Client());
$tokenGenerator = new \Crunch\Salesforce\AccessTokenGenerator();
$accessToken = $tokenGenerator->createFromSalesforceResponse($token);
class SFLocalFileStoreConfig implements \Crunch\Salesforce\TokenStore\LocalFileConfigInterface {
/**
* The path where the file will be stored, no trailing slash, must be writable
*
* @return string
*/
public function getFilePath()
{
return __DIR__;
}
}
$tokenStore = new \Crunch\Salesforce\TokenStore\LocalFile(new \Crunch\Salesforce\AccessTokenGenerator, new SFLocalFileStoreConfig);
//Save a token
$tokenStore->saveAccessToken($accessToken);
//Fetch a token
$accessToken = $tokenStore->fetchAccessToken();
$sfConfig = new SalesforceConfig();
$sfClient = new \Crunch\Salesforce\Client($sfConfig, new \GuzzleHttp\Client());
$sfClient->setAccessToken($accessToken);
$data = $sfClient->search('SELECT Email, Name FROM Lead LIMIT 10');