I am creating a trgger that will fire an error when a particular picklist value has been selected three times. This works and the error message displays.
I now need the error to display if a date from a date field has been selected three times.
I have been told that trigger.old and trigger.new is a way of achieving this, but I am having trouble understanding it completely.
I will provide my trigger so far. Many thanks.
trigger FiveAsideQuantityTrigger on Opportunity (before insert,before update) {
Integer count =[select count() from Opportunity WHERE Select_Area__c='5-a-side Pitch' AND Start_Time__c!=null];
for(Opportunity a:trigger.new){
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='09:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='10:00'){
a.addError('5-a-side Pitch is fully booked at this time.');
}
}
}