PHP code example of antogkou / laravel-salesforce

1. Go to this page and download the library: Download antogkou/laravel-salesforce library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antogkou / laravel-salesforce example snippets


use Antogkou\LaravelSalesforce\Facades\Salesforce;

// Basic request
$response = Salesforce::get('/endpoint');

// With custom user context
$response = Salesforce::setEmail('[email protected]')
    ->get('/endpoint');

// With custom headers
$response = Salesforce::post('/endpoint', $data, [
    'Custom-Header' => 'Value'
]);

// Set custom user email for the request
$response = Salesforce::setEmail('[email protected]')
    ->get('/endpoint');

// With query parameters
$response = Salesforce::get('/endpoint', [
    'limit' => 10,
    'offset' => 0
]);

// With custom headers
$response = Salesforce::post('/endpoint', $data, [
    'Custom-Header' => 'Value'
]);

// Handling responses
$response = Salesforce::get('/endpoint');

if ($response->successful()) {
    $data = $response->json();
    $status = $response->status();
} else {
    $error = $response->json('error');
}

use Antogkou\LaravelSalesforce\Exceptions\SalesforceException;
use Illuminate\Http\Client\RequestException;

try {
    $response = Salesforce::get('/endpoint');
} catch (SalesforceException $e) {
    // Handle Salesforce-specific errors
    $details = $e->getDetails(); // Array of error details
    $status = $e->getCode();     // HTTP status code
} catch (RequestException $e) {
    // Handle HTTP client errors
}
bash
# Publish config file
php artisan vendor:publish --tag="salesforce-config"

# If using certificate authentication
php artisan vendor:publish --tag="salesforce-certificates"