myoutdesk/salesforcerest

There is no license information available for the latest version (0.1.3) of this package.

Simple REST library for Salesforce

0.1.3 2023-03-08 19:11 UTC

This package is not auto-updated.

Last update: 2024-11-14 03:12:08 UTC


README

Salesforce Rest API Example

Contains code for basic rest API implementation in php using username\password flow for API only account.

Salesforce Setup

  1. Salesforce Sandbox -> Setup -> Create -> Apps
  2. Create new custom app with Oauth Enabled & Device Flow Enabled
  3. Copy the Consumer Key & Consumer Secret
  4. 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)');