Salesforce CRM Integration with Website
Salesforce is an enterprise CRM platform with broad customization capabilities. Website integration with Salesforce allows automatic lead creation from forms, customer database synchronization, transaction data transmission, and building a unified customer profile for sales managers.
Connection Methods
REST API (Salesforce REST API) — primary option. Authentication via OAuth 2.0 (Connected App). Supports CRUD operations on Salesforce objects (Lead, Contact, Account, Opportunity).
Salesforce Web-to-Lead — built-in HTML form from Salesforce. Simplest option, but limited capabilities: no validation, no custom fields, difficult to customize appearance. Suitable only for simple cases.
Salesforce Platform Events / Streaming API — for real-time bidirectional synchronization.
Connected App Setup
- In Salesforce: Setup → App Manager → New Connected App
- Enable OAuth settings, add callback URL
- Select scopes:
api,refresh_token - Get Consumer Key and Consumer Secret
Creating Lead from Order Form
use Omniphx\Forrest\Providers\LaravelServiceProvider;
// composer require omniphx/forrest
// config/forrest.php
'credentials' => [
'consumer_key' => env('SF_CONSUMER_KEY'),
'consumer_secret' => env('SF_CONSUMER_SECRET'),
'username' => env('SF_USERNAME'),
'password' => env('SF_PASSWORD'),
]
// In controller
Forrest::authenticate();
$lead = Forrest::sobjects('Lead', 'post', [
'body' => [
'FirstName' => $request->first_name,
'LastName' => $request->last_name,
'Email' => $request->email,
'Phone' => $request->phone,
'Company' => $request->company ?? 'Individual',
'LeadSource' => 'Website',
'Description' => "UTM: {$request->utm_source}/{$request->utm_campaign}"
]
]);
Order Synchronization (Opportunities)
Confirmed order on website → Opportunity in Salesforce linked to Contact/Account. This allows managers to see purchase history directly in CRM.
Forrest::sobjects('Opportunity', 'post', [
'body' => [
'Name' => "Order #{$order->id}",
'AccountId' => $salesforceAccountId,
'Amount' => $order->total / 100,
'CloseDate' => $order->created_at->format('Y-m-d'),
'StageName' => 'Closed Won',
'Order_ID__c' => $order->id // custom field
]
]);
Bidirectional Synchronization
Changes in Salesforce (deal status, contact details) should reflect on the website. Implementation via Outbound Messages or Platform Events: Salesforce sends webhook to website when object changes.
Alternative — periodic polling: every 15 minutes query changed objects via SELECT Id, ... FROM Lead WHERE LastModifiedDate > {timestamp} via SOQL.
Contact Deduplication
Salesforce often contains duplicates — need logic: before creating new Lead/Contact, check for existing records with same email via SOQL query.
$existing = Forrest::query(
"SELECT Id, Email FROM Lead WHERE Email = '{$email}' LIMIT 1"
);
if ($existing['totalSize'] > 0) {
// Update existing lead
Forrest::sobjects("Lead/{$existing['records'][0]['Id']}", 'patch', [...]);
} else {
// Create new
}
Field Mapping
Custom fields in Salesforce are created via Setup → Object Manager. API name of custom field ends with __c (e.g., UTM_Source__c). Field mapping website → Salesforce fields is stored in config so code doesn't change when structure changes.
Error Handling and Queues
Salesforce API has limits (24-hour API call limits). All requests to Salesforce are executed via queue (Laravel Queue/Horizon) so response isn't blocked and retries happen on temporary errors.
Development time: 4–6 weeks for complete bidirectional integration with custom objects and order synchronization.







