Sub topic 4
Linking Activities to the Right Records
This chapter assumes you know what a record, an object and a property are, and that you can read a deal's stage and amount. You should also know the activity types from the previous chapter: calls, emails, meetings, notes and tasks. Here you learn how an activity attaches to deals, contacts and companies, and what goes wrong when it attaches to the wrong ones.
Why links matter more than the text
An activity is only useful if people can find it from the record they are looking at. A note that says "Budget confirmed" is worth nothing if it sits on no deal timeline. A rep opening the deal, a manager running a pipeline report and an automation rule waiting for "a call in the last 7 days" all follow links. They do not search note text.
So every activity needs two kinds of link:
- Which deal or account is this about? This is the business context.
- Who was involved? This is the person context.
Salesforce and HubSpot answer these two questions with different mechanisms, but the idea is the same.
How Salesforce links activities
Salesforce stores calls, tasks and similar items in the Task object, and meetings in the Event object. Each has two relationship fields:
| Field | Name | Points to | Cardinality |
|---|---|---|---|
| `WhoId` | Name | A Contact or Lead (a person) | One primary person, plus optional extra people through related-contact settings |
| `WhatId` | Related To | An Opportunity, Account, Case, or other non-person object | One record |
Note the asymmetry. An activity has exactly one WhatId. If a call covers two opportunities, you must log two activities, or pick the one that matters most and mention the other in the description.
The example below creates a completed call. It links the call to an opportunity through WhatId and to a contact through WhoId.
Task t = new Task(
Subject = 'Discovery call with Dana Lee',
Type = 'Call',
Status = 'Completed',
ActivityDate = Date.today(),
Description = 'Confirmed budget owner. Next step: send pricing by Friday.',
WhatId = opportunityId,
WhoId = contactId
);
insert t;Here opportunityId and contactId are variables that already hold valid record IDs. The script does not define them.
Account roll-up
When WhatId is an Opportunity, Salesforce also shows the activity on the related Account's activity timeline. You get this without a second link. You do not get the reverse. An activity with WhatId set to an Account does not appear on any of that account's opportunities.
Link to the most specific record you can, which is normally the Opportunity. The Account timeline then still shows the activity.
Checking what was linked
Use a subquery to read back the activities on an opportunity. This query returns open activities (not yet completed) and the history (completed activities).
SELECT Id, Name, StageName, CloseDate,
(SELECT Subject, ActivityDate, Status FROM OpenActivities),
(SELECT Subject, ActivityDate FROM ActivityHistories)
FROM Opportunity
WHERE Id = :opportunityIdBecause the query is written inside Apex or the Developer Console, :opportunityId is a bind variable. In a plain query tool, replace it with a literal ID.
If your call is missing from the results, its WhatId is almost certainly set to something else, often the Account.
How HubSpot links activities
HubSpot models this differently. An activity (call, email, meeting, note or task) is its own object. It has no single "Related To" field. Instead it has associations: typed links between two records. One note can be associated with many records at the same time: a deal, two contacts and a company.
HubSpot records two kinds of association:
- Association category.
HUBSPOT_DEFINEDassociations are built in.USER_DEFINEDassociations are custom labels your account added, such as "Decision maker". - Association type ID. A number that names the direction and the object pair. For example, a note to a deal uses
214, and the reverse direction uses a different ID.
The following example creates a note and associates it with a deal in the same request.
import os
import requests
url = "https://api.hubapi.com/crm/v3/objects/notes"
headers = {
"Authorization": f"Bearer {os.environ['HUBSPOT_TOKEN']}",
"Content-Type": "application/json",
}
body = {
"properties": {
"hs_timestamp": "2026-11-27T15:00:00Z",
"hs_note_body": "Demo went well. Next step: security review on Dec 4.",
},
"associations": [
{
"to": {"id": os.environ["DEAL_ID"]},
"types": [
{"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 214}
],
}
],
}
resp = requests.post(url, headers=headers, json=body, timeout=30)
resp.raise_for_status()
print(resp.json()["id"])This note links to the deal only. It does not link to the contact who attended. To get a contact association, add a second entry to the associations list with that contact's ID and the note-to-contact type ID. Look up the exact IDs in HubSpot's association documentation or through its associations schema endpoint before you hard-code any.
Association propagation in the UI
When you log an activity in the HubSpot interface, it usually pre-fills associations. If you log from a contact's page, the contact is associated, and HubSpot may suggest the contact's company and open deals. Accept or remove each suggestion deliberately. Over-association is the most common HubSpot error: one call stamped onto five deals makes every deal look active.
Comparing the two models
| Question | Salesforce | HubSpot |
|---|---|---|
| Where is the link stored? | Fields on the activity (`WhoId`, `WhatId`) | Association records between the activity and each target |
| Deals per activity | One (`WhatId`) | Many |
| People per activity | One primary, others through related contacts | Many |
| Company link | Indirect, through the Opportunity's or Contact's Account | Direct association, or inferred |
| Custom link meaning | Not available on the standard fields | Association labels |
A decision guide for linking
Apply these rules in order:
- If the conversation moved a specific deal forward, link that deal.
- Link every person who took part, not only your main contact. Their timelines then show the history, and reports on contact engagement stay accurate.
- Link the company when no deal exists yet, such as early prospecting.
- Do not link a deal you only mentioned in passing.
Common errors
- Logging against the account when a deal exists. In Salesforce, this keeps the activity out of opportunity reports. Fix it by editing
WhatId. - Logging against the contact only. The contact timeline shows the activity, but the deal does not. Forecast reviews then say "no activity in 30 days" when there was a call yesterday.
- Wrong deal among several. A company with a renewal and an expansion deal open at once invites mix-ups. Check the deal name and amount before you save.
- Duplicate contacts. If two records exist for Dana Lee, the activity goes to one and the other looks silent. Merge duplicates, or search by email address when you pick the contact.
- Hard-coded IDs. Stage and association IDs can differ between accounts or after customization. Look them up per account instead of copying from an example.
- Over-association in HubSpot. One activity attached to every open deal inflates activity counts.
Permissions and visibility
You can link an activity only to records you can see, and who sees the activity depends on the records it is linked to. In Salesforce, sharing rules and the Opportunity's access can hide an activity from a colleague even when the activity itself is not private. In HubSpot, team and record-level permissions work in a similar way. If a manager says they cannot see your call, check the link and the permission before you assume the log failed.
Worked example
You run a demo for Acme with Dana Lee (budget owner) and Raj Patel (IT). Acme has one open deal, "Acme - Annual Platform License", and a separate closed-won deal from last year.
In Salesforce:
- Create a Task with
Type = 'Call'or an Event for the meeting. - Set
WhatIdto the open opportunity, not last year's. - Set
WhoIdto Dana, the main contact. Add Raj through the related-contacts feature, if enabled. - Query
OpenActivitiesandActivityHistoriesto confirm.
In HubSpot:
- Create the meeting or note.
- Associate the open deal, Dana, Raj and the Acme company.
- Leave last year's deal unassociated.
- Open the open deal's timeline and confirm the entry.
Exercise
A Salesforce rep logs a call with WhatId set to the Acme Account instead of the open Acme Opportunity. The opportunity's activity report shows no recent calls. Why, and how do you fix it?
Show answer
The activity links to the Account, and Salesforce does not push Account-level activities down to opportunities, so the opportunity's OpenActivities and ActivityHistories do not include it. Edit the activity so WhatId is the Opportunity ID. The Account timeline will then still show the call, because Opportunity activities roll up to the Account.
Exercise
In HubSpot you need one note to appear on a deal, on two contacts and on their company. How do you do that in a single API call, and what must you look up first?
Show answer
Send one POST to the notes endpoint with four entries in the associations array: one for the deal, two for the contacts and one for the company. Each entry has the target record ID and a types list with associationCategory and the correct associationTypeId for note-to-deal, note-to-contact or note-to-company. First look up those type IDs in HubSpot's association documentation or schema endpoint, because they differ by object pair.
Exercise
A customer has a renewal deal and an expansion deal open. A single call discussed both. How should it be logged in Salesforce and in HubSpot?
Show answer
In Salesforce, an activity has only one WhatId, so log two activities, one per opportunity, or link the more important one and name the other in the description. In HubSpot, create one activity and associate both deals, plus the participating contacts and company.