Prevent account record from being edited if the record is created 7 days back.

Not all records in Salesforce are meant to be edited indefinitely. Sometimes, business logic requires locking down data after a specific period—especially when it’s tied to approvals, compliance, auditing, or financial reporting. One simple but effective use case is restricting edits to Account records once they’ve been in the system for more than 7 days.

In this blog, we walk you through an Apex trigger that prevents users from editing Account records that were created more than 7 days ago. The logic is clean, bulk-safe, and enforced using a simple validation inside the before update context.

This is the kind of automation that reinforces data protection, process adherence, and reduces unwanted changes to critical CRM data.

đź§  Why This Trigger Is Important


In many business processes, Account data becomes a reference point for contracts, audits, integrations, or downstream processes. Once that data is locked in—especially after onboarding, approval, or KYC—it should not be modified casually. With this trigger:

  • Records created more than 7 days ago become non-editable

  • You reduce the risk of accidental or unauthorized changes

  • You enforce process boundaries and governance

  • Teams maintain data integrity across departments and systems

  • Business workflows tied to Account data become more reliable

This approach gives your Salesforce org better control over how and when data can be changed—without complex flows or custom permissions.

🔍 What This Blog Covers


  • How to use a before update Apex trigger to stop edits

  • How to calculate the number of days since a record was created

  • Why using CreatedDate < System.today() - 6 accurately reflects a 7-day range

  • How to use addError() to prevent a DML operation from proceeding

  • Why this technique supports data control and user accountability

  • How to write clean, scalable logic using a handler class

This trigger helps you lock down critical data based on lifecycle or timeline rules, adding a layer of intelligent data governance to your CRM.

🎯 Real-World Use Cases for This Trigger


  • Financial or legal orgs where Accounts must be locked after onboarding

  • Compliance-driven industries where records should not be altered post-verification

  • Subscription or B2B services where changes to master records can affect billing

  • Sales teams who need Account info frozen after approvals

  • Admin teams who want to automate record protection without using record types or complex sharing rules

This automation is especially helpful when data control needs to be enforced based on age of record, not user role or profile.

Solution:

trigger AccountTrigger on Account (before update) {
        if(Trigger.isUpdate){ if(Trigger.isBefore){
                                       AccountTriggerHandle.preventAccEdit(Trigger.new);
                         }
         }
}
public class AccountTriggerHandle{ public static void
              preventAccEdit(List<Account> accList){ for(Account acc:accList){ if(acc.CreatedDate<System.today()-6){
              acc.addError(‘You cannot update
               account created 7 days back’);
                                             }
                             }
               }
}

Want to Apply As Content Writer?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

Let's get you started!

Interested in writing Salesforce Content?

Fill in this form and we will get in touch with you :)