myoutdesk / salesforcerest
Simple REST library for Salesforce
Installs: 1 232
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- guzzlehttp/guzzle: ^7.4
README
Salesforce Rest API Example
Contains code for basic rest API implementation in php using username\password flow for API only account.
Salesforce Setup
- Salesforce Sandbox -> Setup -> Create -> Apps
- Create new custom app with Oauth Enabled & Device Flow Enabled
- Copy the Consumer Key & Consumer Secret
- Login using API only user
Installation
composer require myoutdesk/salesforcerest
Usage
Default API version is 42.0, production is off by default. Your wrapper can be tested using a mock handler.
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 }
Create Record
$salesforceRest->create('Lead', [ 'FirstName' => 'John', 'LastName' => 'Smith', 'Company' => 'Company Name, LLC' ]);
Create Multiple Records
// 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 Record
// Get all fields $salesforceRest->get('Lead', ID); // Get only specific fields $salesforceRest->get('Lead', ID, ['Phone', 'customfield__c', 'email']);
Get Multiple Records
// Requires api 42.0 $salesforceRest->getCollection('Lead', [ID, ANOTHER_ID], ['firstName', 'lastName']);
Update Record
$salesforceRest->update('Account', ID, ['Phone' => '123-1234-123'])
Update Multiple Records
// 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 ]);
Delete Record
$salesforceRest->delete('Lead', ID);
Delete Multiple Records
// Requires api 42.0 $salesforceRest->deleteCollection([ID, ANOTHER_ID]);
Search For Record
$salesforceRest->search('FIND {email@email.com} IN ALL FIELDS RETURNING Lead(Id, Name, Email)');