function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Albert RaulAlbert Raul 

Trigger for the opportunity

Don't want the user to enter a future close date, if they do opportunities with past closed should be entered 
Arun Kumar 1141Arun Kumar 1141

Hello Albert,

Below are the code:

Apex Code

public class OppRecord {
    public static void function(List<Opportunity> oppList){
        for(opportunity opp: oppList){
            if(opp.closeDate < System.today()){
                opp.addError('Please Enter a Future Closed Date');
            }
        }
    }
}

Trigger

trigger FutureClosedDate on Opportunity (before insert) {
    if(trigger.isBefore && trigger.isInsert){
        OppRecord.function(trigger.new);
    }
}

If you find the above code helpful, please mark it as the best answer.

Thank you.