DEV Community

Michael
Michael

Posted on • Originally published at getmichaelai.com

Building the Ultimate CRM Bridge: A Developer's Guide to Salesforce HubSpot Integration

Sales and marketing misalignment is a tale as old as time. Sales teams live and breathe Salesforce, while marketing teams orchestrate campaigns in HubSpot. When these two systems don't talk, data gets siloed, leads get dropped, and sales and marketing alignment becomes a pipe dream.

In this CRM integration guide, we will walk through how to effectively connect Salesforce to HubSpot. We'll cover the native setup, data mapping, and for the builders out there, how to handle custom synchronization logic using Node.js for advanced B2B marketing automation.

Prerequisites for the Sync

Before diving into the technical weeds, ensure you have:

  • HubSpot Account: Professional or Enterprise edition (Marketing, Sales, or Service Hub).
  • Salesforce Account: API access enabled (Enterprise, Unlimited, or Developer Edition).
  • Permissions: System Administrator access in both platforms.

Step 1: The Native Salesforce HubSpot Integration

HubSpot provides a robust native connector. For 90% of use cases, this managed package is exactly what you need.

  1. In HubSpot, navigate to Marketplace > App Marketplace.
  2. Search for "Salesforce" and click Install App.
  3. Log in to your Salesforce environment to authorize the OAuth 2.0 connection.
  4. Install the HubSpot integration package into Salesforce (install for All Users).

This creates a bi-directional sync pipeline. But simply connecting the pipes isn't enough—you have to define what data is allowed to flow through them.

Step 2: Object Mapping and Sync Rules

A successful Salesforce HubSpot integration relies on strict data governance. By default, the systems map the following standard objects:

  • HubSpot Contacts <--> Salesforce Leads / Contacts
  • HubSpot Companies <--> Salesforce Accounts
  • HubSpot Deals <--> Salesforce Opportunities

Pro-Tip for Integration Engineers: Always configure sync rules to prevent API limit exhaustion. Decide which system is the source of truth (usually HubSpot for marketing interactions, Salesforce for sales pipeline data) and use HubSpot Inclusion Lists to restrict which contacts are pushed to Salesforce.

Step 3: Customizing the Sync with Code (Webhook Approach)

Sometimes, the native sync doesn't cover complex, bespoke business logic. Let's say you want to trigger a highly specific custom Apex REST endpoint in Salesforce whenever a contact hits a specific lead nurturing workflow stage in HubSpot.

You can use HubSpot Webhooks in a workflow to send a payload to a middleware (like AWS Lambda or a Node.js server), which then formats and sends the data to Salesforce via its REST API.

Here's a simple Node.js/Express snippet demonstrating this middleware concept:

const express = require('express');
const axios = require('axios');
const app = express();

app.use(express.json());

// Endpoint to receive HubSpot Webhook
app.post('/hubspot-webhook', async (req, res) => {
    try {
        const hubspotData = req.body;
        // Extract email and custom score from the payload
        const email = hubspotData.properties.email.value;
        const leadScore = hubspotData.properties.hubspotscore.value;

        // Custom logic: Only push to Salesforce if lead score exceeds threshold
        if (leadScore > 50) {
            await pushToSalesforce(email, leadScore);
            console.log(`Successfully synced ${email} to Salesforce.`);
        }

        res.status(200).send('Webhook processed');
    } catch (error) {
        console.error('Integration Error:', error);
        res.status(500).send('Server Error');
    }
});

// Function to authenticate and push to Salesforce REST API
async function pushToSalesforce(email, score) {
    // Assume sfToken is retrieved via OAuth 2.0 JWT Bearer flow
    const sfToken = process.env.SF_ACCESS_TOKEN;
    const sfDomain = process.env.SF_DOMAIN;

    const payload = {
        Email: email,
        Custom_Lead_Score__c: score
    };

    // Upserting Lead record in Salesforce using Email as the external ID
    await axios.patch(`${sfDomain}/services/data/v55.0/sobjects/Lead/Email/${email}`, payload, {
        headers: {
            'Authorization': `Bearer ${sfToken}`,
            'Content-Type': 'application/json'
        }
    });
}

app.listen(3000, () => console.log('Middleware listening on port 3000'));
Enter fullscreen mode Exit fullscreen mode

Step 4: Powering the Lead Nurturing Workflow

Once the API pipelines are secure, you can confidently build out your B2B marketing automation.

  1. Lead Capture: A user downloads a technical whitepaper via a HubSpot form.
  2. Scoring & Nurturing: They enter a lead nurturing workflow in HubSpot, receiving targeted educational drip emails.
  3. Handoff: Once their lead score hits the defined threshold (e.g., 50, as handled in our Node.js script or the native connector settings), the integration syncs the Contact to Salesforce as an MQL (Marketing Qualified Lead).
  4. Sales Action: The assigned Salesforce rep receives a task notification to follow up, bridging the gap for perfect sales and marketing alignment.

Watch Out for These Pitfalls

API Call Limits

Salesforce imposes strict 24-hour API limits. If you bulk import 100,000 records into HubSpot, the bi-directional sync can easily blow through your Salesforce API quota. Always use Inclusion Lists to selectively sync records.

State and Country Picklists

If your Salesforce instance uses strict validation rules for State and Country picklists, ensure HubSpot's dropdowns perfectly match Salesforce's ISO codes. A mismatch here is the #1 cause of silent sync failures.

Deduplication

Always enforce uniqueness rules using email addresses (for leads/contacts) and website domain names (for accounts/companies) as your external identifiers to prevent database pollution.

Wrapping Up

Successfully implementing a Salesforce HubSpot integration means creating a unified revenue engine. Whether you rely entirely on the native managed package or build custom middleware to handle edge cases, the goal remains the same: establishing a seamless data flow that empowers marketers and gives developers peace of mind.

Originally published at https://getmichaelai.com/blog/how-to-integrate-salesforce-with-hubspot-a-step-by-step-b2b-

Top comments (0)