Suppose I have a scenario where I want to restrict the user from updating the Account record multiple times if the record is already updated within that 1 hour. Write a trigger for this scenario.
SituationalSenior Salesforce DeveloperSalesforce DeveloperTo restrict updates to the Account record within one hour, I would implement an after update trigger that checks the last updated timestamp. First, I’d create a custom field on the Account object to store the last updated date. In the trigger, I’d query for the last update time and compare it to the current time. If the difference is less than one hour, I’d prevent the update by throwing an exception.
This approach ensures that users cannot make multiple updates within a short timeframe, which is crucial for maintaining data integrity. The main trade-off here is user experience; users may feel restricted if they need to make changes frequently. To judge success, I would track the number of blocked updates and gather user feedback to ensure the restriction aligns with business needs.