After Trigger
Learning Content
Last updated: July 21, 2026
After Trigger
An After Trigger is an Apex Trigger that executes after Salesforce writes the record to the database but before the transaction is committed. At this stage, the record has a valid Salesforce Record Id (for newly inserted records), allowing developers to perform operations that depend on the existence of the record in the database.
After Triggers are commonly used to create related records, update parent records, synchronize data with other objects, publish platform events, and execute complex business logic that requires the record Id.
💡 LearnFrenzy Insight
Imagine purchasing a new car.
Only after the vehicle has been officially registered does it receive a registration number. Once that number exists, insurance, financing, and registration certificates can all be created.
Similarly, an After Trigger executes only after Salesforce assigns the record Id, enabling related processes that depend on that identifier.
Where Does After Trigger Execute?
User Clicks Save
│
▼
System Validation
│
▼
Before-Save Flow
│
▼
Before Trigger
│
▼
Validation Rules
│
▼
Duplicate Rules
│
▼
Database Save
│
▼
⭐ After Trigger
│
▼
Workflow / Flow
│
▼
Commit Transaction
At this stage, Salesforce has written the record to the database transaction and assigned an Id for newly inserted records. However, the transaction is still active and can be rolled back if a later operation fails.
Why Use an After Trigger?
| Capability | Description |
|---|---|
| Create Related Records | Create child records using the newly assigned Record Id. |
| Update Parent Records | Synchronize summary or related information. |
| Cross-Object Processing | Perform automation across multiple Salesforce objects. |
| Publish Platform Events | Notify downstream systems or subscribers. |
| Complex Business Automation | Implement advanced post-save business processes. |
Common Use Cases
| Business Requirement | After Trigger Solution |
|---|---|
| Create Opportunity Team Members | Create related records after the Opportunity receives an Id. |
| Create Child Records | Create Contacts, Cases, Tasks, or custom records. |
| Update Parent Totals | Recalculate parent information after child changes. |
| Publish Platform Events | Notify external subscribers of business events. |
| Cross-Object Synchronization | Update related Salesforce objects. |
Simple Apex Example
trigger AccountAfterTrigger on Account (after insert) {
List contacts = new List();
for(Account acc : Trigger.new){
contacts.add(new Contact(
LastName = 'Primary Contact',
AccountId = acc.Id
));
}
insert contacts;
}
The trigger creates a default Contact for every new Account. This is only possible because the Account Id is available in an After Trigger.
Real Business Scenario
🏢 Business Example
When a new Opportunity is created:
- Create a default Opportunity Team Member.
- Create follow-up Tasks.
- Create a related custom implementation record.
- Publish a Platform Event for downstream systems.
All these operations require the Opportunity Id, making an After Trigger the appropriate solution.
Before Trigger vs After Trigger
| Feature | Before Trigger | After Trigger |
|---|---|---|
| Record Id Available | No (Insert) | Yes |
| Create Child Records | No | Yes |
| Modify Same Record | Recommended | Not Recommended |
| Best For | Preparing the record before save. | Post-save automation. |
| Typical Operations | Field updates and validation. | Related records and cross-object processing. |
When Should You Use an After Trigger?
| Use After Trigger | Avoid After Trigger |
|---|---|
| Create child records. | Simple same-record field updates. |
| Publish Platform Events. | Formatting field values. |
| Update related objects. | Basic default values. |
| Cross-object automation. | Logic better suited to Before-Save Flow. |
| Business processes requiring Record Id. | Unnecessary recursive updates. |
🔍 Behind the Scenes: What Happens Internally?
Database Save Completed
│
▼
Record Id Assigned
│
▼
After Trigger Starts
│
▼
Related Records Created
│
▼
Parent Records Updated
│
▼
Workflow / Flow Executes
│
▼
Commit Happens Later
Although the record exists within the current database transaction, Salesforce has not yet permanently committed the transaction. If an unhandled exception occurs later, Salesforce rolls back the record and every related operation executed within the same transaction.
Why After Trigger Matters
| Reason | Benefit |
|---|---|
| Record Id Exists | Supports creation of related records. |
| Supports Cross-Object Logic | Synchronize multiple Salesforce objects. |
| Works with Parent-Child Relationships | Create dependent records immediately. |
| Enables Advanced Automation | Supports enterprise business processes. |
✅ Best Practice
Keep After Triggers bulkified, use Trigger Handler frameworks, perform DML outside loops, and avoid unnecessary updates to the same object to reduce the risk of recursion.
⚠️ Common Mistake
Using an After Trigger to update fields on the same record. Since the record has already been written to the database, this requires another DML update and may cause recursion or unnecessary performance overhead.
🎯 Interview Tip
Question: Why can't a Before Trigger create child records that require the parent Record Id?
Answer: During a before insert trigger, Salesforce has not yet assigned a Record Id to the new parent record. Child records that require a lookup or master-detail relationship cannot reliably reference the parent until the parent Id exists, which is why an after insert trigger is the appropriate place for this type of processing.
📌 Quick Revision
- ✔ Executes after the Database Save Process.
- ✔ Record Id is available.
- ✔ Best for creating related records.
- ✔ Supports cross-object automation.
- ✔ Transaction is still not committed.
- ✔ Rollback is still possible.
- ✔ Avoid updating the same record unless absolutely necessary.
➡ Next Lesson
In the next lesson, you'll learn about Assignment Rules, Auto-Response Rules, and Escalation Rules, including how these platform automations execute after the record is saved and how they fit into the Salesforce Order of Execution.
Practice What You've Learned
Test your understanding with these practice exercises