Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthewpoer/php-salesforce-wrapper
A PHP wrapper for some common Lightning Platform REST API functions
https://github.com/matthewpoer/php-salesforce-wrapper
api lightning pest php rest salesforce
Last synced: 1 day ago
JSON representation
A PHP wrapper for some common Lightning Platform REST API functions
- Host: GitHub
- URL: https://github.com/matthewpoer/php-salesforce-wrapper
- Owner: matthewpoer
- License: wtfpl
- Created: 2018-09-12T15:23:35.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-02T01:41:41.000Z (over 4 years ago)
- Last Synced: 2024-04-18T07:25:34.931Z (7 months ago)
- Topics: api, lightning, pest, php, rest, salesforce
- Language: PHP
- Size: 6.84 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-salesforce-wrapper
## Using Pest for REST
[Pest](https://github.com/educoder/pest) is a PHP client library for RESTful web services. I found it to be a minimal and effective back-bone for this project. The Pest dependency is handled by composer.Thanks @Educoder!
## Composer Install
```sh
composer require matthewpoer/php-salesforce-wrapper:dev-master
```## Get Started
### Authentication
Authentication with Salesforce occurs upon instantiation of the wrapper.
```php
try {
$sfdc = new php_sfdc_wrapper(
SFDC_BASE_URL,
SFDC_CLIENT_ID,
SFDC_CLIENT_SECRET,
SFDC_USERNAME,
SFDC_PASSWORD,
SFDC_SECURITY_TOKEN
);
} catch (\Exception $e) {
$log->critical('Error authenticating with Salesforce. Exception occurred.', array(
'Exception' => $e->getMessage()
));
die('Error authenticating with Salesforce. Exception occurred.' . PHP_EOL);
}
```### Create an Account
```php
try {
$account_id = $sfdc->create('Account', array(
'BillingCity' => 'San Francisco',
'BillingCountry' => 'United States',
'BillingPostalCode' => '94105',
'BillingState' => 'California',
'BillingStreet' => 'The Landmark @ One Market Suite 300',
'Name' => 'Salesforce.com',
));
} catch (\Exception $e) {
$message = $e->getMessage();
$log->critical($message);
die('Error creating Salesforce Account. Exception occurred.' . PHP_EOL);
}
```### Delete an Account
```php
try {
$account_id = $sfdc->delete('Account', $account_id);
} catch (\Exception $e) {
$message = $e->getMessage();
$log->critical($message);
die('Error deleting Salesforce Account. Exception occurred.' . PHP_EOL);
}
```### Find an Account by Name
The `query` method accepts as parameters,
1. an s0bject name
2. an array of fields desired in the result, defaulting to just the `Id` and `Name` fields
3. an string to use as the SOQL query's `WHERE` clause
4. a boolean on whether or not a result should be required (default TRUE). If this is TRUE then the wrapper will throw an exception when no records are found matching the conditions in the `WHERE` clause.```php
try {
$accounts = $sfdc->query(
'Account',
array('Id','Name'),
"name='Salesforce.com'",
FALSE
);
foreach($accounts as $account) {
echo "Found account with ID of " . $account['Id'] . PHP_EOL;
}
} catch (\Exception $e) {
$message = $e->getMessage();
$log->critical($message);
die('Error querying for the Salesforce Account. Exception occurred.' . PHP_EOL);
}
```