PHP code example of myoutdesk / salesforcerest

1. Go to this page and download the library: Download myoutdesk/salesforcerest 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/ */

    

myoutdesk / salesforcerest example snippets


use MyOutDesk\SalesforceRest\SalesforceClient;

$salesforceRest = new SalesforceRest(new \GuzzleHttp\Client());
$connected = $salesforceRest->connectApp(CONSUMER_KEY, CONSUMER_SECRET)
				->asUser(SALESFORCE_USER, SALESFORCE_PASSWORD)
				->authenticate();
if($connected) {
	// good to go
}

$salesforceRest->create('Lead', [
	'FirstName' => 'John',
	'LastName' => 'Smith',
	'Company' => 'Company Name, LLC'
]);

// Requires api 42.0
$leadOne = [
    'firstName' => 'John',
    'lastName' => 'Smith',
    'Company' => 'Company Name, LLC'
];

$leadTwo = [
    'firstName' => 'Alex',
    'lastName' => 'Smith',
    'Company' => 'Company Name, LLC'
];

$salesforceRest->insertCollection('Lead', [$leadOne, $leadTwo]);    

// Get all fields
$salesforceRest->get('Lead', ID);
// Get only specific fields
$salesforceRest->get('Lead', ID, ['Phone', 'customfield__c', 'email']);

// Requires api 42.0
$salesforceRest->getCollection('Lead', [ID, ANOTHER_ID], ['firstName', 'lastName']);

$salesforceRest->update('Account', ID, ['Phone' => '123-1234-123'])

// Requires api 42.0
$leadOne = [
    'id' => ID,
    'firstName' => 'LEAD ONE',
    // other fields here
];

$leadTwo = [
    'id' => ANOTHER_ID,
    'firstName' => 'LEAD TWO',
    // other fields here
];

$salesforceRest->updateCollection('Lead', [ $leadOne, $leadTwo ]);

$salesforceRest->delete('Lead', ID);

// Requires api 42.0
$salesforceRest->deleteCollection([ID, ANOTHER_ID]);

$salesforceRest->search('FIND {[email protected]} IN ALL FIELDS RETURNING Lead(Id, Name, Email)');