Sub topic 1
How a CRM stores deals, people and activity
Before you log a call or move a deal, you need to know where that information is stored. A CRM (customer relationship management system) is a database with a web interface on top. Every later chapter in this tutorial, such as stages, activity types, associations and API logging, builds on the storage model described here.
Prerequisites
This chapter assumes you have the following:
- A working picture of a B2B sales process: a lead is qualified, becomes a deal, and is closed won or lost.
- Comfort moving around a web application and reading JSON.
- Optional: basic Python or SOQL (Salesforce's query language) to run the two small examples. You can skip them and still follow the chapter.
You do not need admin rights. Read access to a Salesforce org or a HubSpot account, such as a free developer account, is enough to try the examples.
The model in one paragraph
Every CRM stores data in three layers:
- An object is a type of thing the CRM tracks, such as a company, a person, a deal or a call.
- A record is one instance of an object, such as one particular deal.
- A property is one attribute of a record, such as the deal's amount or close date.
HubSpot uses the word property and Salesforce uses the word field. They mean the same thing in this chapter.
Records point at other records. A deal points at the company that is buying. A call points at the deal it was about. These pointers let you ask questions like "show every call on this deal." They also explain most data quality problems, because a record with a missing or wrong pointer is stored but hard to find.
Objects, records and properties
Think of an object as a table, a record as a row and a property as a column. The analogy is accurate enough to predict behavior.
- Every record has a system-generated unique ID. Salesforce IDs are 15 or 18 characters, for example
006xx000001abcDAAA. The first three characters identify the object, and006is an Opportunity. HubSpot IDs are numeric strings, such as31548127790, stored in thehs_object_idproperty. A HubSpot ID is unique only within its object type. A contact and a deal can have the same number. - Every property has a data type. Common types are text, number, currency, date, date and time, picklist (a fixed list of allowed values), checkbox and lookup (a reference to another record). The type controls validation, sorting and which reports can use the property.
- Properties have two names. A human-readable label is what users see. An internal name is what the API and queries use. Renaming a label does not change the internal name.
The internal name matters as soon as you write code. In HubSpot the deal "Amount" label corresponds to the internal name amount, but "Deal Stage" is dealstage. In Salesforce, custom fields end in __c, for example Budget_Confirmed__c.
Standard and custom
Both CRMs ship with standard objects and properties and let administrators add custom ones. A team that wants to track the number of seats in a deal can add a custom number property to the deal object. If the team needs something that has no standard object, such as "Implementation Project," an admin can create a custom object. Custom Salesforce objects also end in __c.
Customization is why the same product behaves differently in two companies. Always check what your own account contains before you copy a field name from documentation.
The core sales objects
The following table shows the objects this tutorial uses and what each stores.
| Concept | Salesforce object | HubSpot object | What it stores |
|---|---|---|---|
| Company that buys | Account | Company | Name, industry, size, domain |
| Person at a company | Contact | Contact | Name, email, job title, phone |
| Unqualified prospect | Lead | Contact with a lifecycle stage (a Leads object also exists on some plans) | Early-stage person or company before qualification |
| Sales opportunity | Opportunity | Deal | Amount, stage, close date, owner |
| Call, email, meeting, note, task | Task, Event, EmailMessage | Call, Email, Meeting, Note, Task | A logged piece of activity |
Two differences cause most confusion:
- Leads. In Salesforce, a Lead is a separate object. When the lead qualifies, you convert it, and Salesforce creates an Account, a Contact and optionally an Opportunity from it. HubSpot has no conversion step in the same sense. A person is a contact from the start, and a property called lifecycle stage records how far along they are.
- Deals versus opportunities. The two terms mean the same thing. This tutorial writes "deal" for both unless a section is specific to Salesforce.
Where activity fits
An activity is a record of something that happened or needs to happen: a call, an email, a meeting, a note or a task. Later chapters cover each type. What matters here is how activities are stored.
In HubSpot, activities are objects with their own records. A note has an ID, properties (hs_note_body, hs_timestamp) and associations to other records. HubSpot's API groups calls, emails, meetings, notes and tasks together as engagements, and you create each one the same way you create a deal.
In Salesforce, activities are stored on two standard objects:
- Task holds calls, to-dos and logged emails. A call is a Task whose
Typeor subject says so, and it has aStatusandActivityDate. - Event holds calendar entries with a start and end time, which is where meetings live.
Salesforce's EmailMessage object stores email content in some setups, for example when email-to-case or Enhanced Email is in use.
Salesforce also offers a combined view called activities in the UI. In SOQL, you query relationships such as OpenActivities (upcoming or incomplete) and ActivityHistories (completed) instead of a single table.
The key design point is that an activity is not stored inside a deal. It is a separate record that points at the deal.
How records point at each other
Records are linked in two ways, and the terminology differs by CRM.
Salesforce relationships. A lookup field stores the ID of another record. Opportunity.AccountId is a lookup to the Account. A master-detail relationship is a stricter parent-child link where deleting the parent deletes the children. Salesforce activities use two special polymorphic lookups, meaning they can point at several object types:
WhoIdpoints at a person: a Contact or a Lead.WhatIdpoints at a non-person record: an Account, an Opportunity or a custom object.
A person can be involved in several deals, so Salesforce uses a junction object, OpportunityContactRole, to connect one Opportunity to many Contacts with a role such as Decision Maker.
HubSpot associations. HubSpot stores links as associations between two records. An association can be many-to-many, so one contact can be linked to several deals and one deal to several contacts. Associations can carry labels such as "Decision maker" or "Primary." Each association type has a numeric type ID. The HubSpot example in the spine uses ID 214 for note-to-deal, which comes from HubSpot's defined set.
The diagram below shows the Salesforce version.
HubSpot's version has the same shape. Contacts, companies and deals are linked by associations, and each activity record is associated with whichever of them it concerns.
The next chapters cover association rules and defaults in detail. For now, remember that a link is data like any other. If nobody creates it, the CRM does not infer it.
Seeing the model in your own account
Do not trust documentation alone. Ask your account what it contains.
Salesforce: follow a relationship with SOQL
In Salesforce, a query can reach through a lookup using dot notation. Run this in the Developer Console's Query Editor or in Workbench:
SELECT Id, Name, StageName, Amount, CloseDate,
Account.Name, Owner.Name
FROM Opportunity
ORDER BY CloseDate DESC
LIMIT 5Account.Name follows the AccountId lookup and returns the buyer's name. Owner.Name follows the owner lookup to a User record. This is one query across three objects, and no join syntax is needed because the relationship is part of the schema.
HubSpot: list the properties of an object
HubSpot's Properties API returns every property defined on an object, including custom ones. This script prints the first ten deal properties with their internal name, data type and field type. It uses a private app token stored in an environment variable.
import os
import requests
url = "https://api.hubapi.com/crm/v3/properties/deals"
headers = {"Authorization": f"Bearer {os.environ['HUBSPOT_TOKEN']}"}
resp = requests.get(url, headers=headers, timeout=30)
resp.raise_for_status()
for prop in resp.json()["results"][:10]:
print(prop["name"], prop["type"], prop["fieldType"], sep=" | ")Look for dealname, amount, dealstage, closedate and pipeline. Those are the internal names you will use when you create deals through the API later in the tutorial. Check any custom properties your team added. Their names are the ones your reports depend on.
What this means for logging
The storage model has four practical consequences.
- The record is only as good as its links. A call logged with no association exists in the database but does not appear on the deal's timeline. Reports that start from deals will not count it.
- Properties are typed. You cannot save "next week" in a date field. A picklist rejects values that are not on its list, and a number field rejects text. When an API call fails validation, check the type first.
- IDs identify records, names do not. Two companies can both be called "Acme." Code and integrations should use IDs, or a unique property such as an email address or domain.
- Customization varies. Stage names, required fields and custom objects belong to your account. Learn what yours has before you log data.
Common mistakes at this level
- Treating a contact as the deal. A contact is a person. The deal holds the money, stage and close date. Putting deal information in contact notes hides it from pipeline reports.
- Duplicating companies. Two Account or Company records for the same buyer split the deal history. Match on domain before you create a new record.
- Using labels in code. Labels change when an admin edits them. Internal names are stable.
- Forgetting that activities are separate records. Deleting a deal does not always delete its calls and emails. Salesforce deletes related activities with their parent in many cases. HubSpot keeps the associated records but removes the link. Check your CRM's behavior before cleaning up data.
Exercise
A rep logs a completed call in Salesforce. The Task's WhoId is set to the Contact "Dana Lee," but WhatId is empty. The sales manager's report lists all calls per Opportunity, and this call does not appear. Why, and which one field change fixes it?
Show answer
The report groups calls by the Opportunity they are linked to, and that link is stored in WhatId. With WhatId empty, the Task is linked only to a person, so it has no Opportunity to be grouped under. Setting WhatId to the Opportunity's ID links the call to the deal and makes it appear in the report.
Exercise
You need to write a script that creates a HubSpot deal with the amount from a form field labeled "Deal Value." What do you check before choosing the property name for the API body, and what do you check about the property's type?
Show answer
Look up the internal name of the property in the account's deal property settings or through the Properties API, because the label "Deal Value" may not match the internal name (the standard amount property is amount). Then check its type and field type, for example number or currency, so the value you send passes validation.