Sub topic 12
Data quality, permissions and common pitfalls
This chapter assumes you can log calls, emails, meetings, notes and tasks against deals, and that you know how associations link them to contacts and companies. It also assumes you have seen the Salesforce and HubSpot API examples from earlier chapters. Here you will learn how logged data goes bad, how to detect that with queries, how permissions change what you can see and write, and which habits prevent most problems.
What "good data" means
A CRM record is only useful if someone can trust it when making a forecast or a follow-up decision. Data quality is usually judged on five dimensions.
| Dimension | Question it answers | Example failure |
|---|---|---|
| Completeness | Are the required fields and links present? | A call Task has no `WhatId`, so no deal shows it. |
| Accuracy | Does the value match reality? | The amount is 48000 but the signed contract says 42000. |
| Timeliness | Was it recorded while it was still useful? | A demo is logged three weeks later with the wrong outcome. |
| Consistency | Do people record the same thing the same way? | One rep writes "Closed Won", another writes "won - PO pending". |
| Uniqueness | Does each real-world thing exist once? | Two Acme companies, each holding half the deal history. |
Most pitfalls below break one of these five. Naming the dimension helps you choose the fix. Incomplete data calls for a required field. Inconsistent data calls for a picklist, which is a field limited to a fixed list of values.
Common pitfalls and how to recognize them
Activities linked to the wrong record, or to none
In Salesforce, WhatId points at the related record (an Opportunity, Account or similar) and WhoId points at a person (a Contact or Lead). If you set only WhoId, the Task appears on the contact but not on the Opportunity. In HubSpot, an activity with no deal association never appears on the deal timeline, and deal reports that count activities will miss it.
A second variant is the contact with several deals. A rep logs a call from the contact's page, and HubSpot associates it with the contact and company only. The deal owner never sees it. Associate the activity with the deal explicitly, or log from the deal record.
Stale deals
A stale deal is open but has had no activity, or has a close date in the past. Stale deals inflate pipeline totals and weaken forecasts. Common causes:
- Reps update the stage but never move the close date.
- Deals nobody wants to close as lost stay open "just in case".
- A next step was logged in a note but never created as a task, so nothing reminds anyone.
Duplicate records
Duplicates come from manual entry, list imports, and email sync creating a contact from an unknown address. They split activity history across several records. Merge them using the CRM's duplicate tools. Salesforce has duplicate and matching rules, and HubSpot has a duplicate management tool. Merging keeps the history, but the merge itself is hard to undo, so review each pair first.
Integrations create a different kind of duplicate. A script that retries after a timeout can create the same note twice, because neither CRM treats a repeated POST or insert as the same request. Before retrying, search for the record you may already have created, or store your own external ID and check it first.
Free text where a picklist belongs
Free-text fields such as "Lost reason" or "Next step type" can't be grouped in reports. "Price", "pricing", "too expensive" and "$$" all mean the same thing, but a report counts them as four values. Use a picklist for anything you plan to count.
Skipped or backdated stages
If reps can jump a deal from an early stage to Closed Won, your stage-conversion reports show nothing useful. Likewise, if a deal's closedate is moved only when it is already late, the forecast is wrong. Fix this at the source with required fields per stage and validation rules (see below).
Wrong stage IDs in API calls
HubSpot deal stages are internal IDs, not the labels people see. The appointmentscheduled value in the earlier example works only in an unmodified default pipeline. A customized pipeline has different IDs, and a script that hard-codes the old ones may fail or put deals in the wrong stage. Read the pipeline's stages from the API or the settings page before you write the script.
Time zones and dates
HubSpot's hs_timestamp is stored in UTC. A call logged at 23:30 local time may appear on the next day in reports. Salesforce's ActivityDate is a date with no time zone, while CreatedDate is a timestamp. Pick one field for "when it happened" and use it consistently.
Auto-captured noise
Email and calendar sync saves time but can log internal messages, recruiting threads or personal appointments. Review your sync settings. Exclude your own company's domain, and decide whether messages are logged for everyone or only for contacts that already exist.
Detecting problems with queries
Reports and queries are your audit tool. This SOQL query finds open Opportunities with no activity in 30 days, or none ever. LastActivityDate is a standard field on Opportunity that Salesforce maintains for you.
SELECT Id, Name, StageName, CloseDate, LastActivityDate, Owner.Name
FROM Opportunity
WHERE IsClosed = false
AND (LastActivityDate = null OR LastActivityDate < LAST_N_DAYS:30)
ORDER BY CloseDateThis one finds open Opportunities whose close date has already passed:
SELECT Id, Name, StageName, CloseDate, Owner.Name
FROM Opportunity
WHERE IsClosed = false
AND CloseDate < TODAY
ORDER BY CloseDateFor HubSpot, use the CRM search endpoint. This script lists open deals whose close date is in the past. It reads the token from an environment variable and follows paging so it doesn't stop at the first 100 results.
import os
from datetime import datetime, timezone
import requests
url = "https://api.hubapi.com/crm/v3/objects/deals/search"
headers = {
"Authorization": f"Bearer {os.environ['HUBSPOT_TOKEN']}",
"Content-Type": "application/json",
}
now_ms = int(datetime.now(timezone.utc).timestamp() * 1000)
body = {
"filterGroups": [
{
"filters": [
{"propertyName": "hs_is_closed", "operator": "EQ", "value": "false"},
{"propertyName": "closedate", "operator": "LT", "value": str(now_ms)},
]
}
],
"properties": ["dealname", "dealstage", "closedate", "amount"],
"limit": 100,
}
while True:
resp = requests.post(url, headers=headers, json=body, timeout=30)
resp.raise_for_status()
data = resp.json()
for deal in data["results"]:
p = deal["properties"]
print(deal["id"], p.get("dealname"), p.get("closedate"))
after = data.get("paging", {}).get("next", {}).get("after")
if not after:
break
body["after"] = afterRun checks like these on a schedule, such as a weekly dashboard or a report subscription, instead of once. A one-time cleanup decays within a quarter if nothing changes in how people enter data.
Permissions
Permissions decide who can see a record, who can edit it, and whether an API call succeeds. They are a frequent cause of "I logged it but it's missing" reports.
Salesforce
Salesforce layers several controls, and a user needs all of them to line up:
- Object permissions come from the profile and permission sets. A user needs Create on Task to insert one, and Read on Opportunity to see it.
- Field-level security can hide or make read-only individual fields, such as
Amount. - Record access comes from the organization-wide default, the role hierarchy, sharing rules and ownership. If a user can't see the Opportunity, they can't see its activities either.
- Activity sharing is tied to the related records. A Task is generally visible to users who can see the record in
WhatIdorWhoId, plus its owner and users above the owner in the role hierarchy. Check your org's settings, because admins can change this.
Failures through the API show up as errors such as INSUFFICIENT_ACCESS_OR_READONLY or FIELD_INTEGRITY_EXCEPTION. Apex code runs in system mode by default and ignores the user's object and field permissions. Declaring a class with sharing enforces record sharing, but not object or field permissions. If your code acts on behalf of users, check Schema.sObjectType.Task.isCreateable() or use Security.stripInaccessible.
HubSpot
HubSpot controls access in these places:
- User permissions set whether a user can view, edit, create or delete each object type, and whether that applies to all records, only their own, or their team's.
- Teams and ownership limit "own" and "team" access. A deal belongs to its owner, and record access follows that ownership.
- Private app scopes limit the API token. A token that has deal read access but not write access fails with a 403 when you try to create a note. Grant the narrowest set of scopes the script needs, and read the exact scope names in the current API documentation for each object.
Least privilege, with exceptions
Give users edit access to the records they work on, and restrict who can delete or bulk-edit. Deletion is the dangerous permission. Salesforce keeps deleted records in the Recycle Bin for a limited time and HubSpot has a restore option, but restoring doesn't always bring back every relationship, so don't rely on it. Limit bulk import and merge rights to a few trained people.
For integrations, use a dedicated integration user (Salesforce) or a private app (HubSpot) rather than a person's credentials. Then logged records show a clear source, and the integration keeps working when someone leaves the company.
Guardrails that prevent bad data
Fixing data after the fact costs more than blocking bad entries. Use these controls in both systems:
- Required fields at stage gates. Require amount and close date before a deal leaves the early stages, and require a lost reason before Closed Lost. Salesforce does this with validation rules or path settings. HubSpot does it with required properties on stage change.
- Picklists over free text. Use them for reasons, sources and activity outcomes.
- Default associations. Create activities from the deal page, so the deal is associated automatically.
- Duplicate prevention. Turn on matching rules in Salesforce, and use HubSpot's duplicate management. Use an external ID field on records you sync from other systems.
- Idempotent integrations. Search before create, and log the CRM record ID your script receives, so a retry can find the original.
- A sandbox for testing. Test scripts against a Salesforce sandbox or a HubSpot developer test account. Test records in production show up in forecasts.
A short audit routine
Once a week, or once a month for small teams, run through this list:
- Open deals with a close date in the past.
- Open deals with no activity in 30 days.
- Deals in late stages with no amount, or with an amount of zero.
- Activities with no deal association.
- Contacts or companies that look like duplicates (same domain, same email).
- Closed Lost deals with no lost reason.
Send each result to the record owner with a due date, rather than fixing everything centrally. Owners know the real status, and it keeps the habit with the people who create the data.
Exercise
A rep says she logged a call on Dana Lee's contact record, but the deal owner can't see it on the opportunity. She is sure the call exists. List two things to check and the fix for each.
Show answer
First, check whether the Task has the Opportunity in WhatId (Salesforce) or a deal association (HubSpot). If it only references the contact, the activity never appears on the deal. Fix it by adding the deal association, and log future calls from the deal record. Second, check whether the deal owner has access to the deal and its activities, through role, sharing, or team and ownership rules. If they can't see the deal, the activity is hidden for them as well. Fix it by adjusting the sharing or access setting, not by copying the call.
Exercise
A nightly script creates a HubSpot note for each meeting. After a network timeout, it retried and the deal now shows two identical notes. Name the cause and two changes that prevent it.
Show answer
The CRM treats each POST as a new record, so a retried request after a timeout can create a second note when the first one actually succeeded. Prevent it by searching for an existing note (for example, by a stored external reference or matching timestamp and body) before creating one, and by recording the returned note ID for each meeting so the script knows what is already logged. Adding a bounded retry with a check before each attempt also helps.
Exercise
Write a SOQL query that returns open Opportunities with a close date in the past, showing the owner's name, ordered by close date.
Show answer
SELECT Id, Name, StageName, CloseDate, Owner.Name FROM Opportunity WHERE IsClosed = false AND CloseDate < TODAY ORDER BY CloseDate