Add Integrations
By the end of this lesson, you'll be able to:
- Add a Slack notification integration when a Project's health becomes At Risk
- Apply Module 36's async-callout-from-trigger rule one final time
- Decide against an external object for this specific integration, and explain why
Prerequisites: "Add Async Processing"
The notification, as a Queueable callout
public class SlackNotificationQueueable implements Queueable, Database.AllowsCallouts {
private List<Id> projectIds;
public SlackNotificationQueueable(List<Id> projectIds) {
this.projectIds = projectIds;
}
public void execute(QueueableContext qc) {
for (Project__c p : [SELECT Id, Name FROM Project__c WHERE Id IN :projectIds]) {
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Slack_Webhook');
req.setMethod('POST');
req.setBody(JSON.serialize(new Map<String, Object>{
'text' => 'Project "' + p.Name + '" is now At Risk.'
}));
new Http().send(req);
}
}
}
ProjectHealthService (or the batch job from Lesson 6) enqueues this job when it detects a health change to At Risk — Module 36\'s exact rule still applies: this callout cannot happen synchronously inside a trigger-originated transaction, so it runs as a Queueable, just like Module 42\'s ledger integration.
Why NOT an external object here
Module 44 introduced external objects for cases where an external system is the authoritative source of truth and must be queried live. Slack is not a data source this application needs to query — it is purely a one-way notification target. An external object would be the wrong tool entirely; this is a textbook case for a simple outbound callout instead, exactly the kind of deliberate tool-matching Module 44\'s closing lesson asked for.
A failed notification does not lose the underlying data
If the Slack webhook is briefly unreachable, the Project__c.Health__c update itself has already committed by the time this Queueable runs — Module 39\'s and Module 42\'s "the primary operation is never lost because a downstream notification failed" principle, applied here one final time.
Exercise
As a comment, explain why an external object (Module 44) would be the wrong tool for this Slack integration, even though both external objects and this Queueable approach involve an outside system.
Show hint
Think about whether this application ever needs to query Slack for data.
Add Integrations Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
This lesson adds an outbound Slack notification whenever a Project's health changes to At Risk — Module 36's Queueable-callout pattern, reused here, alongside an explicit decision about why an external object (Module 44) would NOT be the right tool for this specific integration.