adrianbaez/easysf-bundle
Symfony bundle that simplifies working with Salesforce by providing basic configuration and helper services to connect, authenticate, and run common API operations in Symfony apps. Useful for quick SF integration without heavy setup.
Installation Add the package via Composer:
composer require adrianbaez/easysf-bundle
Register the bundle in config/app.php under providers:
Adrianbaez\EasySfBundle\EasySfBundle::class,
Configuration Publish the default config:
php artisan vendor:publish --provider="Adrianbaez\EasySfBundle\EasySfBundle" --tag="config"
Edit config/easysf.php to set up your Salesforce credentials (consumer key, consumer secret, callback URL, etc.).
First Use Case: OAuth Authentication Trigger the OAuth flow via a route or controller:
use Adrianbaez\EasySfBundle\Facades\EasySf;
// Redirect to Salesforce for auth
return EasySf::authenticate();
// Handle callback (e.g., in a route)
$token = EasySf::handleCallback();
OAuth Flow Integration
EasySf::authenticate() in a controller to redirect users to Salesforce for authentication./salesforce/callback) and process it with EasySf::handleCallback().API Calls
$accounts = EasySf::get('/services/data/vXX.X/sobjects/Account');
$newAccount = ['Name' => 'Test Account'];
EasySf::post('/services/data/vXX.X/sobjects/Account', $newAccount);
SOQL Queries
$results = EasySf::query('SELECT Id, Name FROM Account LIMIT 10');
Bulk API (Legacy)
$jobId = EasySf::bulkInsert('/services/data/vXX.X/jobs/ingest', 'Account', $data);
public function handle($request, Closure $next) {
if (!EasySf::isAuthenticated()) {
return redirect()->route('salesforce.auth');
}
return $next($request);
}
easysf.authenticated or easysf.error events.Deprecated Package
league/oauth2-salesforce for modern Laravel (8+).OAuth Callback Handling
config/easysf.php matches Salesforce’s registered redirect URI exactly (including http/https).storage/logs/laravel.log for OAuth errors (e.g., invalid_grant).API Versioning
EasySf::get() if needed:
EasySf::get('/services/data/v56.0/sobjects/Account');
Token Expiry
try {
$token = EasySf::getAccessToken(); // May auto-refresh
} catch (\Exception $e) {
// Re-authenticate or handle refresh logic
}
debug: true in config/easysf.php to log API requests/responses.tap:
$response = EasySf::get('/path')->tap(function ($response) {
\Log::info('Raw Response:', $response->getBody());
});
try {
$data = EasySf::get('/path');
} catch (\Adrianbaez\EasySfBundle\Exceptions\EasySfException $e) {
\Log::error($e->getMessage());
abort(500, 'Salesforce API error');
}
Custom Endpoints
Override the base URL in the config or extend the EasySf facade to add custom methods:
// app/Providers/AppServiceProvider.php
public function boot() {
EasySf::extend(function ($client) {
$client->customMethod = function ($endpoint) {
return $client->get($endpoint);
};
});
}
Model Bindings Create a trait to bind Salesforce records to Eloquent models:
use Adrianbaez\EasySfBundle\Facades\EasySf;
trait SalesforceBindable {
public static function findBySfId($sfId) {
$response = EasySf::get("/services/data/vXX.X/sobjects/Account/{$sfId}");
return new static((array) $response);
}
}
Webhook Handling If using Salesforce Platform Events, manually parse incoming webhooks and trigger Laravel events:
// routes/web.php
Route::post('/salesforce/webhook', function (Request $request) {
$payload = $request->json()->all();
event(new SalesforceWebhookReceived($payload));
});
How can I help you explore Laravel packages today?