Do not allow edit the Opportunity record if the record is created 7 days back from System.Today() | Do not allow a user to modify the Opportunity record if the Opportunity is created before 7 days from today

260 views

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

Why Should You Schedule Meeting?

🎯 If You Are Facing Any Of These 6 Challenges. Schedule Meeting With Me.

  • Learn Salesforce Development
  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 

 

Create Apex Trigger β†’

Step 1:- Create Apex Controller : OpportunityTrigger.apxt

SFDX:Create Apex Trigger>> New >> OpportunityTrigger.apxt

OpportunityTrigger.apxt [Apex Trigger]

  1.      TRIGGER OpportunityTrigger ON Opportunity (BEFORE UPDATE, after UPDATE) {
  2.     IF(TRIGGER.isBefore && TRIGGER.isUpdate){
  3.         OpportunityTriggerHandler.preventRecUpdate(TRIGGER.new);
  4.     }ELSE IF(TRIGGER.isAfter){
  5.  
  6.     }
  7. }

 

Create Trigger Handler Controller β†’

Step 2:- Create Apex Controller : OpportunityTriggerHandler.apxc

SFDX:Create Apex Trigger>> New >> OpportunityTriggerHandler.apxc

OpportunityTriggerHandler.apxc [Trigger Handler]

  1.  
  2.   public class OpportunityTriggerHandler {
  3.  
  4.     public static void preventRecUpdate(List<Opportunity> oppList){
  5.         FOR(Opportunity op:oppList){
  6.             IF(op.CreatedDate < system.today() - 7){
  7.                 op.addError('Do not allow update record 7 days back created');
  8.             }
  9.         }    
  10.     }    
  11. }

 

Further post that would you like to learn in Salesforce

 

FAQ (Frequently Asked Questions)

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




Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net