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
Andrew Hoban 14Andrew Hoban 14 

Trigger if a date from a date field has been selected three times

Hi all,

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 am unsure how i would implement this inside my trigger.
Any help would be appreciated. Thanks.

Trigger:
trigger SevenAsideQuantityTrigger on Opportunity (before insert,before update) {

Integer count =[select count() from Opportunity WHERE Select_Area__c='7-a-side Pitch' AND Start_Time__c!=null];
for(Opportunity a:trigger.new){
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='09:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='10:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='11:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
if(count==2&&a.Select_Area__c=='7-a-side Pitch'&& a.Start_Time__c=='12:00'){
a.addError('7-a-side Pitch is fully booked at this time.');
}
}
}

 
ManjunathManjunath

Hi Andrew,

Are you trying to check the date field value with other 2 date field in the record. If  yes then

1: As you are iterating the Opportunity records.
2: get that specific data value store it into variable.
3: then compare this with those 2 data value.
4: it satisfied use a.addError();

Regards
MCS

Andrew Hoban 14Andrew Hoban 14
Thanks for your reply. I am tryting to fire an error message if the picklist value and the same date value has been selected two or more times. I am unsure how I would implement this into my trigger.

Thanks
ManjunathManjunath
Am still not clear what you want, but see if group by will help you.