Efficient task management is essential to productivity, especially in Salesforce where users rely on timely follow-ups, scheduled calls, and to-do lists to keep business moving forward. However, when Tasks are created manually or via automation, users sometimes forget to assign a Priority—leading to miscommunication or low visibility of important activities.
In this blog, we walk you through a simple yet impactful Apex trigger that ensures every new Task record created in Salesforce has its Priority automatically set to “High”. This default behavior helps your team prioritize better, reduces manual data entry, and enforces consistent record values across your org.
This trigger runs in the before insert context, ensuring the Priority value is set before the record is saved to the database.
🧠 Why Setting Task Priority Automatically Is Important
Manually assigning priorities can lead to:
-
Inconsistent or missing Priority values
-
Reduced visibility into urgent tasks
-
Missed follow-ups or SLA breaches
-
Lower agent productivity
By automatically setting the Priority to High, you ensure all new tasks are treated with urgency—especially helpful for new leads, service requests, or internal escalations. This tiny automation removes one more step for users and improves your team’s responsiveness.
🔍 What This Blog Covers
-
How to create a
before insert
trigger on the Task object -
How to assign default values using Apex
-
Benefits of automating field population
-
How this pattern can be extended to other fields and objects
-
Best practices for keeping triggers clean and bulk-safe
This blog is a great starting point for those new to Apex triggers or looking to build smarter defaulting logic in their Salesforce org.
🎯 Real-World Use Cases
-
Sales Teams: Automatically highlight follow-up tasks with prospects as high priority
-
Customer Support: Mark every new case-related task as important
-
Marketing Campaigns: Ensure tasks related to lead nurturing are surfaced first
-
Operations: Auto-prioritize tasks assigned from automated workflows or integrations
Even better—this logic can be modified or extended to set different priorities based on record type, subject, or task type.
👨💻 Developer & Admin Tips
Here’s how the logic works:
-
The Apex trigger fires during the before insert event.
-
It loops through each Task in
Trigger.new
. -
For each Task, it sets the
Priority
field to'High'
. -
Since this happens before the record is saved, no DML operations are required.
This logic is:
-
Bulk-safe: Handles multiple task records in one go
-
Governor-limit friendly: No SOQL or DML inside loops
-
Simple and scalable: Can be extended later with conditions
You can expand the logic like this:
-
Set Priority only if it’s currently blank
-
Use different priorities based on the task’s Subject
-
Make it configurable via Custom Metadata or Custom Settings
-
Add logging for auditing automated field updates
Testing recommendations:
-
Create a Task from the UI, API, and Flow
-
Verify that the Priority is set to High
-
Try bulk inserting tasks via Data Loader
-
Ensure there are no errors in the debug logs
This approach works well in production environments and supports declarative use cases too—like enforcing consistent SLA expectations.
Solution:
trigger TaskTrigger on Task (before insert) {
if(Trigger.isInsert && Trigger.isBefore) {
for (Task taskRecord : Trigger.NEW) {
taskRecord.Priority= ‘High’;
}
}
}