Salesforce how to make the task object read only for specific profiles
•8 min read
Here’s the cleanest Apex-based solution to make Task records non-editable and non-deletable for selected profiles (e.g., Sales User, Marketing User), while still allowing them to view the records. This method ensures you can effectively Make Task object read-only in Salesforce.
⚙️ Apex Trigger: Make Task Read-Only for Specific Profiles
Implementing this approach will help you Make Task object read-only in Salesforce, providing better control over task management for specified user profiles.
Create this trigger on the Task object.
Go to:
Setup → Object Manager → Task → Triggers → New Trigger
Then paste the following code 👇
trigger RestrictTaskAccess on Task (before update, before delete) {
// Fetch current user's profile name
String currentProfileName = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId()].Name;
// Define the profiles that should have read-only access
Set<String> readOnlyProfiles = new Set<String>{
'Sales User', // Change this to your actual profile name
'Marketing User' // Add more profile names as needed
};
// If the user's profile is in the read-only list, block edit/delete actions
if (readOnlyProfiles.contains(currentProfileName)) {
for (Task t : Trigger.new) {
t.addError('You have read-only access to Task records and cannot modify or delete them.');
}
}
}
JavaScript💡 How This Works
- The trigger runs before update and before delete.
- It checks the current user’s Profile Name using
UserInfo.getProfileId(). - If the profile is one of the restricted ones, it blocks the operation by using
t.addError()— this displays an error message and stops the DML action. - The result:
- ✅ The user can still view Tasks.
- ❌ The user cannot edit or delete any Task record.
Related Posts

How to Automatically create a follow-up Task when a Lead is converted

How You need to update a related child record whenever a parent record’s status changes, but only if the status is “Closed Won.” How would you design this in Apex?
