You need to sign in to do that
Don't have an account?
Andrew Hoban 6
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:
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 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.'); } if(count==3&&a.Area_Of_Hire__c=='5-a-side Pitch'&& a.Start_Time__c=='11: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=='12: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=='13: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=='14: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=='15: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=='16: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=='17: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=='18: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=='19: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=='20:00'){ a.addError('5-a-side Pitch is fully booked at this time.'); } } }
read more:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm
http://www.sfdc99.com/2014/02/25/comparing-old-and-new-values-in-a-trigger/
Would I need to use a map in the example i have provided? I am strugging to fully undertant .new and .old.
Thanks