Hey guys, today in this post we are going to learn about How to Do not prevent allow edit the Opportunity record if the record is created 7 days back from System.Today().
Final Output β
Other related post that would you like to learn in Salesforce
Create Apex Trigger β
Step 1:- Create Apex Controller : OpportunityTrigger.apxt
SFDX:Create Apex Trigger>> New >> OpportunityTrigger.apxt
OpportunityTrigger.apxt [Apex Trigger]
TRIGGER OpportunityTrigger ON Opportunity (BEFORE UPDATE, after UPDATE) {
IF(TRIGGER.isBefore && TRIGGER.isUpdate){
OpportunityTriggerHandler.preventRecUpdate(TRIGGER.new);
}ELSE IF(TRIGGER.isAfter){
}
}
Create Trigger Handler Controller β
Step 2:- Create Apex Controller : OpportunityTriggerHandler.apxc
SFDX:Create Apex Trigger>> New >> OpportunityTriggerHandler.apxc
OpportunityTriggerHandler.apxc [Trigger Handler]
public class OpportunityTriggerHandler {
public static void preventRecUpdate(List<Opportunity> oppList){
FOR(Opportunity op:oppList){
IF(op.CreatedDate < system.today() - 7){
op.addError('Do not allow update record 7 days back created');
}
}
}
}
Further post that would you like to learn in Salesforce
How do I lock my record in approval process?
Whenever we create an approval process we get an option to Lock/Unlock records in the initial submission action, final approval, and rejection action. We can also perform the same actions by using apex lock() and unlock() methods in the system approval namespace by passing in record IDs or sObjects.
What is the limitation of validation rule in Salesforce?
You can have up to 100 active rules for an object. Compound fields, including addresses, first and last names, and dependent picklists and lookups cannot be referenced in a validation rule. Workflow rules and some processes can invalidate previously valid fields.
Can we delete any record using validation rule?
Unfortunately validation rules do not work in delete contexts, so a solution using just RH and validation rules would not be possible. The delete operation will go through, and the validation rule won't be able to catch it.
Related Topics | You May Also Like
Our Free Courses β
π Get Free Course β
π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |