Sub topic 10
Automating Follow-up Tasks and Stage-Change Logging
Prerequisites and the automation model
This chapter assumes you understand CRM records, pipeline stages, and the difference between a deal or opportunity and an activity. You should also be able to navigate a CRM administration screen. Knowledge of Apex or JSON is optional.
Automation rules are conditions and actions that run when a record changes. A common rule watches the deal stage. When the stage changes, the CRM creates a follow-up task for the deal owner, assigns a due date, or records the transition for reporting.
A good rule answers four questions:
- What event starts the rule?
- What condition must be true?
- What action should happen?
- How does the system avoid duplicate or unwanted actions?
The important condition is usually “the stage changed,” not merely “the deal has stage X.” If a deal remains in the same stage and another field changes, the rule should not create another identical task.
A stage-change workflow
A typical workflow looks like this:
In Salesforce, use a record-triggered Flow that runs after an Opportunity is updated. Set the entry condition to detect a change in StageName. Then create a Task related to the Opportunity with WhatId.
In HubSpot, create a deal-based workflow. Enroll a deal when its dealstage property changes, branch by the new stage, and use a Create task action. Assign the task to the deal owner and set a stage-specific due date.
A stage transition table makes the intended behavior explicit:
| Stage transition | Automated action | Guard |
|---|---|---|
| Qualification to Demo | Create a task due in two business days | Only when the transition occurs |
| Demo to Proposal | Create a pricing follow-up task | Skip closed or disqualified deals |
| Proposal to Closed Won | No follow-up task | Record the transition for reporting |
Implementing a Salesforce rule with Apex
For teams that manage automation in code, this Salesforce trigger creates one follow-up Task for each Opportunity whose stage changed. The loop is bulk-safe because it collects tasks and performs one insert operation.
trigger OpportunityStageFollowUp on Opportunity (after update) {
List<Task> followUpTasks = new List<Task>();
for (Opportunity currentOpportunity : Trigger.new) {
Opportunity previousOpportunity =
Trigger.oldMap.get(currentOpportunity.Id);
if (currentOpportunity.StageName != previousOpportunity.StageName) {
followUpTasks.add(new Task(
WhatId = currentOpportunity.Id,
Subject = 'Follow up after stage change: '
+ currentOpportunity.StageName,
Status = 'Not Started',
Priority = 'Normal',
ActivityDate = Date.today().addDays(2),
Description =
'Stage changed from '
+ previousOpportunity.StageName
+ ' to '
+ currentOpportunity.StageName
+ '. Confirm the next customer action.'
));
}
}
if (!followUpTasks.isEmpty()) {
insert followUpTasks;
}
}In production, prefer Flow when sales administrators need to change the rule without a deployment. Use Apex when the logic needs complex branching, custom calculations, or integration with other systems. Test the rule with bulk updates, missing owners, closed stages, and repeated edits.
Preventing duplicate and misleading automation
Automation can damage data quality when it creates noise. Add guards such as:
- Do not create tasks for Closed Won or Closed Lost unless the business process requires them.
- Do not create a second task when an equivalent open task already exists.
- Use the deal owner at the time the rule runs, or define a fixed queue for shared work.
- Use business-day calculations when the due date must exclude weekends.
- Keep the stage transition in the task description or a dedicated audit field.
- Log failures so administrators can identify permission or validation errors.
A rule should create a useful next action, not pretend that a customer interaction occurred. A stage-change task is a prompt for a person. It is not proof that a call, email, or meeting happened.
Choosing the right mechanism
| Mechanism | Best for | Main risk |
|---|---|---|
| CRM workflow or Flow | Simple, visible stage-based actions | Configuration drift or excessive rules |
| Email and calendar sync | Capturing messages and meetings automatically | Missing associations or privacy limits |
| API or custom code | External events and complex logic | Authentication, retries, and duplicate records |
| Manual logging | Exceptions and unusual interactions | Inconsistent completion |
Start with one narrowly scoped rule. Measure task completion and duplicate rates before adding more branches. If representatives ignore the tasks, review the timing, owner, wording, and relevance of the action instead of adding more automation.
Exercise
A deal moves from Demo to Proposal, then a representative edits the amount without changing the stage. Should a stage-change workflow create a second Proposal follow-up task? Why?
Show answer
No. The workflow should test whether the stage changed. An amount-only edit is not a new stage transition, so creating another task would produce a duplicate.