Sub topic 11
Checking Your Data with Reports and Queries
Logging a deal or activity is only half the job. You also need to confirm that the record landed where you expected, that it is linked to the right deal, and that the numbers a manager will read are correct. This chapter shows how to check your data with reports in the CRM interface and with queries through the API.
Prerequisites
This chapter assumes you have read the earlier chapters in this tutorial. You should know:
- How deals (Salesforce calls them opportunities), contacts, and companies (Salesforce calls them accounts) relate to each other.
- The activity types: calls, emails, meetings, notes, and tasks.
- How associations link an activity to a deal and to people.
- How to read basic JSON. Optional: basic Python or Apex for the API examples.
Why check your data
A CRM accepts almost anything you type. It does not warn you when a call is attached to the wrong deal, when a close date is in the past, or when a note was saved with no link to any deal. Those mistakes stay invisible until someone builds a forecast from them.
Checking has two goals:
- Verify your own work. After you log something, confirm it is stored and linked correctly.
- Find gaps across many records. Look for deals with no recent activity, no next step, or missing fields.
Reports suit the second goal and quick visual checks. Queries suit precise checks and anything you want to repeat or automate.
The working model: reports versus queries
| Aspect | Report | Query |
|---|---|---|
| Where it runs | CRM user interface | API, developer console, or script |
| Who uses it | Reps, managers, operations | Admins, developers, analysts |
| Output | Table, summary, chart, dashboard | Rows of raw data (often JSON) |
| Strength | Easy to build, shareable, filtered by role | Exact control over fields and relationships |
| Limit | Constrained by report types and joins | Needs syntax knowledge and API access |
| Salesforce name | Reports and dashboards | SOQL (Salesforce Object Query Language) |
| HubSpot name | Custom report builder, deal and activity reports | CRM search API |
Both approaches read the same underlying records. If a report and a query disagree, the cause is usually a filter, a permission, or a date range, not a different copy of the data.
Checking one deal with a query
Start with the most common check: did my activity get logged against the right deal? In Salesforce, the earlier chapter created a call Task linked to an opportunity. A SOQL query can return the opportunity together with its activities.
SELECT Id, Name, StageName, CloseDate,
(SELECT Subject, ActivityDate, Status FROM OpenActivities),
(SELECT Subject, ActivityDate FROM ActivityHistories)
FROM Opportunity
WHERE Id = :opportunityIdRead the query in three parts:
- The outer
SELECTreturns the opportunity fields you care about: name, stage, and close date. OpenActivitiesis a child relationship that returns tasks and events that are not yet complete.ActivityHistoriesreturns completed tasks and past events.
The :opportunityId is a bind variable. It works inside Apex or tools that support binds. In the Developer Console query editor, replace it with a literal ID in single quotes.
This split explains a common surprise. A Task with Status = 'Completed' does not appear under OpenActivities. It appears under ActivityHistories. If you look in the wrong list, you may think the call was never saved.
Expected result
For the discovery call created earlier, the completed Task with subject "Discovery call with Dana Lee" should appear in ActivityHistories. If it is missing, check these causes in order:
- The insert failed or was rolled back. Look for an error from your code.
WhatIdwas set to a different record, so the Task is attached to another deal.- You do not have permission to see the Task.
- The query used the wrong opportunity ID.
Checking a record in HubSpot
HubSpot stores notes, calls, emails, meetings, and tasks as their own objects, linked to deals through associations. To verify a note you created through the API, you can read the associations from the deal.
The Python script below lists the notes associated with a deal. It uses the CRM v3 associations endpoint, then reads each note.
import os
import requests
base = "https://api.hubapi.com"
headers = {"Authorization": f"Bearer {os.environ['HUBSPOT_TOKEN']}"}
deal_id = os.environ["DEAL_ID"]
assoc = requests.get(
f"{base}/crm/v3/objects/deals/{deal_id}/associations/notes",
headers=headers,
timeout=30,
)
assoc.raise_for_status()
for item in assoc.json()["results"]:
note = requests.get(
f"{base}/crm/v3/objects/notes/{item['id']}",
headers=headers,
params={"properties": "hs_note_body,hs_timestamp"},
timeout=30,
)
note.raise_for_status()
props = note.json()["properties"]
print(item["id"], props.get("hs_timestamp"), props.get("hs_note_body"))If the note you created appears in the output, the association worked. If the script prints nothing, the note may exist but not be linked to this deal. Check the association type ID you used when you created it.
The token needs read access to deals and notes. A token with only write scopes for creating records can fail on this read, so confirm the scopes if you get a 403 error.
Building a useful report
A report answers a question about many records at once. Good reports start with a clear question, not with a list of fields. Here are four questions that expose most logging problems.
| Question | What to filter | What it reveals |
|---|---|---|
| Which open deals have had no activity in 14 days? | Open deals, last activity date older than 14 days | Stalled or neglected deals |
| Which open deals have a close date in the past? | Open deals, close date before today | Stale close dates that distort the forecast |
| Which open deals have no next step? | Open deals, next step field is empty | Deals where the agreed follow-up was never recorded |
| Which activities are not linked to any deal? | Activities where the deal association is empty | Orphan records that no deal report will show |
Building the report in Salesforce
- Open Reports and choose New Report.
- Pick the report type. "Opportunities with Activities" (or a similar type your admin provides) joins the opportunity to its activities. Plain "Opportunities" cannot show activity details.
- Set the filter for open opportunities only.
- Add columns: opportunity name, owner, stage, amount, close date, last activity date, and next step.
- Group by owner so each rep sees their own deals together.
- Save the report in a shared folder and run it.
Building the report in HubSpot
- Open Reports and create a custom report.
- Choose the deals data source. Add activities as a related source if your subscription supports it.
- Add a filter for deal stage so closed deals are excluded.
- Add the properties you need, such as last contacted date, close date, and amount.
- Save the report and add it to a dashboard.
Report features depend on your subscription tier and on how your administrator set up report types, so the exact menu names may differ from this outline.
Common reasons the numbers look wrong
When a report or query returns something unexpected, work through this list before changing any data.
- A filter is hiding records. Reports often carry default filters such as "My opportunities" or "This quarter". Remove them to test.
- A date range is too narrow. Activity dates and created dates are different fields. Filter on the one you mean.
- Permissions limit what you see. Both CRMs restrict records by owner, team, or role. Another user may see more rows than you do.
- Time zones shift dates. HubSpot stores
hs_timestampin UTC. A call logged late in the evening in one time zone can show on the next day in another. - The record is in the wrong stage field. Stage names look alike across pipelines. Confirm which pipeline a deal belongs to.
- Duplicates split the activity. Two contact records for the same person can hold separate halves of the history.
Checking data quality on a schedule
A one-time check helps, but problems return. Turn your best checks into a routine.
- Save the four reports from the table above and subscribe to them weekly. Salesforce and HubSpot both support scheduled report emails, subject to your plan.
- Put the key counts on a dashboard, for example the number of open deals with no recent activity.
- Review the list in a pipeline meeting. Deals with an empty next step get one assigned during the meeting.
- For developers, run the SOQL or search API checks from a script and alert when the count rises.
A short Salesforce query for the "no recent activity" check shows how a repeatable test looks:
SELECT Id, Name, StageName, CloseDate, LastActivityDate, OwnerId
FROM Opportunity
WHERE IsClosed = false
AND (LastActivityDate = null OR LastActivityDate < LAST_N_DAYS:14)
ORDER BY LastActivityDate ASC NULLS FIRSTIsClosed = false limits the result to open deals. LastActivityDate is a standard field that Salesforce updates when activities are logged. LAST_N_DAYS:14 is a date literal that means the previous 14 days. Deals with no activity at all have a null value, so the query lists them first.
For close dates in the past, use a similar filter:
SELECT Id, Name, StageName, CloseDate, Amount, OwnerId
FROM Opportunity
WHERE IsClosed = false
AND CloseDate < TODAY
ORDER BY CloseDate ASCEdge cases to know
- Query limits. The Salesforce API returns results in batches and enforces limits on request counts. HubSpot search endpoints return pages of results and apply rate limits. For large checks, follow the paging links instead of assuming one response holds everything.
- Sync delay. Activities captured by email and calendar sync can arrive minutes after the event. Run your check after the sync has had time to finish.
- Field availability.
LastActivityDatereflects logged activities. If your team logs outside the CRM, the field will look stale even when work is happening. - Archived or deleted records. Deleted activities may sit in a recycle bin for a limited time and are excluded from normal queries.
- Custom pipelines. Stage names and internal IDs differ in customized pipelines. A report that filters on a stage label may miss deals in another pipeline that use a different label.
Putting it together: a verification routine
Use this routine after a logging session or an API run.
- Query or open the single deal and confirm the activity exists and shows the right date.
- Confirm the activity is linked to the deal and to the contact.
- Confirm the deal stage, amount, and close date are current.
- Run the "no activity in 14 days" and "close date in the past" reports to see whether your deals appear.
- Fix anything that fails, then re-run the check.
Exercise
A rep inserts a Task in Salesforce with Status = 'Completed' and a WhatId pointing to an opportunity. They run a query that selects only the OpenActivities child relationship and see no rows. Is the Task missing? What should they query instead, and what else could explain an empty result?
Show answer
The Task is probably not missing. Completed tasks are returned by the ActivityHistories relationship, not OpenActivities, so the rep should add or switch to ActivityHistories. If that is also empty, check whether the insert succeeded, whether WhatId points to the intended opportunity, whether the user has permission to see the Task, and whether the query used the correct opportunity ID.
Exercise
Write the filter conditions for a report that finds open deals that are likely stale. Name two separate conditions and explain what each catches.
Show answer
Condition one is "open deals with last activity date older than 14 days (or empty)". It catches deals nobody has touched recently. Condition two is "open deals with close date before today". It catches deals whose expected close date has passed without the deal being closed or the date updated, which distorts the forecast. Both must exclude closed deals so won and lost records do not appear.