+ Start a Discussion
Pavan kumar 546Pavan kumar 546 

Any One Pls Help To write Trigger For Below Senario?

my due date is 25/10/2015.  If I change it to 20/10/2015, I want to be allowed to save. If I change it to 30/10/2015, I want to get an error.
ManojjenaManojjena
Hi Pawan,
Which object you need to write trigger ,Here question is you have any staic date or you want to restrict user to select past date .Only you can change future date .

If yes then try with belwo code ,belwo code is in opportunity if you change closedate to past date it wilgive you error .
 
trigger PastDateRestriction on Opportunity(before update){
    for(Opportunity opp:Trigger.new){
        if(opp.CloseDate!=Trigger.oldMap.get(opp.Id).CloseDate&& opp.CloseDate< Trigger.oldMap.get(opp.Id).CloseDate){
            opp.addError('You can not change to past date ');
        }
    }
}
Change your object name and field name accoringly and let me know if it helps !!
Thanks
Manoj