1. Go to this page and download the library: Download stratease/salesforcery 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/ */
stratease / salesforcery example snippets
use Stratease\Salesforcery\Salesforce\Connection\REST\Authentication\PasswordAuthentication;
use Stratease\Salesforcery\Salesforce\Connection\REST\Client;
use Stratease\Salesforcery\Salesforce\Database\Model;
$authentication = new PasswordAuthentication([
'grant_type' => 'password',
'client_id' => 'your app ID',
'client_secret' => 'your app secret',
'username' => '[email protected]',
'password' => 'password+token',
'authorization_url' => 'https://test.salesforce.com/'
]);
// Typically https://login.salesforce.com, for testing use https://test.salesforce.com
$authentication->setEndpoint('https://test.salesforce.com/');
$client = new Client($authentication);
$response = $client->query("SELECT Id FROM Account LIMIT 1");
// Should output a response with a 'records' key that conains an array of results.
print_r($response);
// Register your connection so the ORM can connect
Model::registerConnection($client);
// Your model to connect to the Salesforce Account object
$account = Your/Models/Account::findOneBy('Id', 'abc123');
use Stratease\Salesforcery\Salesforce\Database\Model;
class Account extends Model
{
// Account maps to Account in Salesforce, nothing else
use Stratease\Salesforcery\Salesforce\Database\Model;
class Product extends Model
{
public static $resourceName = 'Product2';
}
// Account is returned
$account = Account::findOneBy('Name', 'Acme Corp');
// An iterable Collection is returned
$accountCollection = Account::findBy(['OwnerId' => '123', 'Status' => 'Active']); // performs an AND expression on the associative array
foreach($accountCollection as $account) {
echo "\n".$account->Name;
}