iabuhilal / php-salesforce-kit
PHP Salesforce Rest API & Bulk API v2 tool kit
dev-master
2021-01-04 14:57 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ^6.2
- netresearch/jsonmapper: ^3.0
This package is auto-updated.
Last update: 2025-06-05 00:16:07 UTC
README
this is based on
Bijesh Shrestha
bjsmasth@gmail.com
iabuhilal
php rest api
Install
Via Composer
composer require iabuhilal/php-salesforce-kit
Getting Started
Setting up a Connected App
- Log into to your Salesforce org
- Click on Setup in the upper right-hand menu
- Under Build click
Create > Apps
- Scroll to the bottom and click
New
under Connected Apps. - Enter the following details for the remote application:
- Connected App Name
- API Name
- Contact Email
- Enable OAuth Settings under the API dropdown
- Callback URL
- Select access scope (If you need a refresh token, specify it here)
- Click Save
After saving, you will now be given a Consumer Key and Consumer Secret. Update your config file with values for consumerKey
and consumerSecret
Setup
Authentication
$options = [ 'grant_type' => 'password', 'client_id' => 'CONSUMERKEY', 'client_secret' => 'CONSUMERSECRET', 'username' => 'SALESFORCE_USERNAME', 'password' => 'SALESFORCE_PASSWORD AND SECURITY_TOKEN' ]; $salesforce = new iabuhilal\Salesforce\Authentication\PasswordAuthentication($options); $salesforce->authenticate(); $access_token = $salesforce->getAccessToken(); $instance_url = $salesforce->getInstanceUrl(); Change Endpoint $salesforce = new iabuhilal\Salesforce\Authentication\PasswordAuthentication($options); $salesforce->setEndpoint('https://test.salesforce.com/'); $salesforce->authenticate(); $access_token = $salesforce->getAccessToken(); $instance_url = $salesforce->getInstanceUrl();
Query
$query = 'SELECT Id,Name FROM ACCOUNT LIMIT 100'; $sfFunc = new \iabuhilal\Salesforce\SalesforceFunctions(); $sfFunc->query($query);
Create
$data = [ 'Name' => 'some name', ]; $sfFunc->create('Account', $data); #returns id
Update
$new_data = [ 'Name' => 'another name', ]; $sfFunc->update('Account', $id, $new_data); #returns status_code 204
Upsert
$new_data = [ 'Name' => 'another name', ]; $sfFunc->upsert('Account', 'API Name/ Field Name', 'value', $new_data); #returns status_code 204 or 201
Delete
$sfFunc->delete('Account', $id);
Changelog:
2020.09.09
- add closeJob function
2020.09.09
- renamed class from CRUD to SalesforceFunctions
- add create createJob, getAllJobs functions
- add Salesforce description objects