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 

How to make a selection in a picklist not availible after it has been processed as an opportunity

Hi,

I am currently in the process of creating a booking system. It should allow people to choose a specific area (Tennis Court) and time (9:00am) from two different picklists. However now that that area has been booked, there needs to be a way of not letting that area be availible for selection untill the time has passed. I have tried performing this with a trigger, however it does not allow the pricebook to be selected, nor does it let a lead conversion take place. I am unsure weather this can be done through workflows and validation rules. The code to my trigger is as follows:

trigger TriggerToValidateTennisCourt on opportunity (BEFORE INSERT, BEFORE UPDATE)
    {
        LIST<opportunity> li = [SELECT area_to_book__c, Start_Time__c FROM opportunity WHERE area_to_book__c = 'Bowling Green'];
        for(opportunity o :trigger.new)
        {
         if(o.area_to_book__c == 'Tennis Court' && o.Start_Time__c == '09:00' || o.Start_Time__c == '10:00'|| o.Start_Time__c == '11:00'|| o.Start_Time__c == '12:00'|| o.Start_Time__c == '13:00'|| o.Start_Time__c == '14:00'|| o.Start_Time__c == '15:00'|| o.Start_Time__c == '16:00'|| o.Start_Time__c == '17:00'|| o.Start_Time__c == '18:00'|| o.Start_Time__c == '19:00'|| o.Start_Time__c == '20:00')
         {
          for(opportunity existrecord :li)
          {
              if(existrecord.area_to_book__c == o.area_to_book__c){
              o.area_to_book__c.adderror('This area is fully booked. Please select another time.');
              }
              else if(o.area_to_book__c == 'Bowling Green' && o.Start_Time__c == '09:00' || o.Start_Time__c == '10:00'|| o.Start_Time__c == '11:00'|| o.Start_Time__c == '12:00'|| o.Start_Time__c == '13:00'|| o.Start_Time__c == '14:00'|| o.Start_Time__c == '15:00'|| o.Start_Time__c == '16:00'|| o.Start_Time__c == '17:00'|| o.Start_Time__c == '18:00'|| o.Start_Time__c == '19:00'|| o.Start_Time__c == '20:00')
              {
          for(opportunity existrecordBG :li)
          {
             if(existrecordBG.area_to_book__c == o.area_to_book__c){
              o.area_to_book__c.adderror('This area is fully booked. Please select another time.');
              }
          }
         }
        }

    }
    }
    }

Many thanks
logontokartiklogontokartik
I am not sure I understand your logic here and also your requirement, 

Your trigger doesnt look right either, you are selecting the existing opportunities with "Area_to_Book__c" as "Bowling Green", but in your if condition you are checking to see if its "Tennis Court". this condition never executes.

You can also improvise your trigger by putting dates if on top and then area to book under dates, its much cleaner.





Andrew Hoban 14Andrew Hoban 14
Hi, thanks for your responce. This is my first project with salesforce.

I am trying to create a reservation system. I have created a web-to lead form that the customer can fill in. The picklist area to book has a series of areas including tennis court etc. 

The trigger was just a test however im not sure if it would work. Is it even possible for this to work on Opportunity? Once a selection has been picked with a certain time it will be booked untill the time has passed.

Many thanks