1. Go to this page and download the library: Download lyonstahl/salesforce 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/ */
lyonstahl / salesforce example snippets
use LyonStahl\Salesforce\Authenticator\Password;
use LyonStahl\Salesforce\Client;
// Provide endpoint and any Guzzle options in Password::create(), endoint defaults to login.salesforce.com
$auth = Password::create(['endpoint' => 'https://test.salesforce.com/'])->authenticate([
"client_id" => $YOUR_CONSUMER_KEY,
"client_secret" => $YOUR_CONSUMER_SECRET,
"username" => $YOUR_SALESFORCE_USERNAME,
"password" => $YOUR_SALESFORCE_PASSWORD_AND_SECURITY_TOKEN
]);
// Here you may also provide object mappings and desired Salesforce API version
$salesforce = new Client($auth, [], 59);
$select = "SELECT Id, Name FROM Example LIMIT 100";
foreach ($salesforce->query($select) as $object) {
echo "Example {$object->Id} ({$object->Name})\n";
// outputs something like "Example 5003000000D8cuIQAA (Bob)"
}
$select = "SELECT Id, Name FROM Example WHERE Name={name} LIMIT 100";
$name = 'Bob';
foreach ($salesforce->query($select, ['name' => $name]) as $object) {
echo "Example {$object->Id} ({$object->Name})\n";
// outputs something like "Example 5003000000D8cuIQAA (Bob)"
}
use LyonStahl\Salesforce\Record;
class Example extends Record
{
public const TYPE = "Example";
public ?string $Name = null;
}
use LyonStahl\Salesforce\Record;
use LyonStahl\Salesforce\Result;
use Example;
class Team extends Record
{
public const TYPE = "Team";
protected const UNEDITABLE_FIELDS = [
"Manager",
"Members",
...parent::UNEDITABLE_FIELDS
];
public ?Example $Manager = null;
public ?Result $Members = null;
}
use LyonStahl\Salesforce\Record;
use LyonStahl\Salesforce\Validator;
class Example extends Record
{
public ?string $Name = null;
protected function validateField(string $field) : void {
switch ($field) {
case "Name":
Validator::characterLength($this->Name, 2, 100);
return;
default:
parent::validateField($field);
return;
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.