Sub topic 3
Logging Deals and Activities in a CRM: Email and Calendar Sync
This chapter assumes you know the B2B sales stages (lead, qualification, closing), can read JSON, and can read basic Python or Apex for the API examples.
Email and calendar sync
Sync connects your mailbox and calendar to the CRM. Emails and meetings are copied onto matching contact and deal records. The CRM matches each message to a contact by email address, so a contact with a wrong or missing address never receives its emails. Check which mailboxes and calendars are included in sync settings. Sync records that an event happened, but not what was decided. You still need to write the outcome.
Creating activities through the API
Use the API when a process must log activities without someone typing them. This HubSpot example creates a note and associates it with a deal in one 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"])Automating follow-up tasks and stage-change logging
Workflow rules run when a record changes. A common rule creates a follow-up task when a deal moves to a new stage.
| Trigger | Action | Risk |
|---|---|---|
| Deal moves to "Proposal" | Create a task due in 3 days | Tasks pile up if deals move back and forth |
| Deal moves to "Closed Won" | Log a stage-change note | Notes can be created for deals moved by mistake |
Test each rule on a sandbox or a single test deal before turning it on for everyone.
Checking your data with reports and queries
A report or query confirms that activities reached the right deals. This Salesforce SOQL query lists an opportunity with its open and closed activities. Replace the Id with a real opportunity Id:
SELECT Id, Name, StageName, CloseDate,
(SELECT Subject, ActivityDate, Status FROM OpenActivities),
(SELECT Subject, ActivityDate FROM ActivityHistories)
FROM Opportunity
WHERE Id = '006XXXXXXXXXXXXXXX'Data quality, permissions and common pitfalls
- Duplicate contacts split one person's history across two records. Merge them before reporting.
- Missing associations leave activities floating with no deal. Filter reports for activities with no deal.
- Permissions can block a user from editing a deal they do not own, so sync or API calls fail for that user.
- Stage IDs in HubSpot differ between customized pipelines. Look them up in your account first.
flowchart TD
A[Email or calendar event] --> B{Contact email matches?}
B -- Yes --> C[Activity linked to contact]
B -- No --> D[Activity unlinked]
C --> E[Associated to deal]
E --> F[Report shows activity on deal]Q: A meeting appears in the calendar but not on the deal. What is the most likely cause, and how do you check it? A: The attendee's email address on the contact record does not match the address in the calendar event. Compare the two addresses, correct the contact, then confirm the activity appears on the deal.