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
StormConsultingStormConsulting 

Custom validation rule - query database

Hi all,

I have the 'Event Management' app installed, which lets us manage bookings for all of our rooms. Our problem is, when adding a booking, we need a validation rule to query the Booking object and see if that room is already booked for that date.

Is it possible to check this from a validation rule? Or what other alternatives is there?

Cheers
Nazeer AhamedNazeer Ahamed
Validation rule won't work here. Probably you have to do it with S-control.

StormConsultingStormConsulting
Ok, how can it be done with an S-control? Is it possible to hook into the create method and place the validation there?

The other alternative is to create my own add/edit page as an S-control, but hoping to avoid this.
Nazeer AhamedNazeer Ahamed

Idea is to create a link facilitated by S-control and place it in the left narrow screen.
S-control will give list of available rooms to book or what you want like.

StormConsultingStormConsulting
Ok that's an idea but it would not stop the user double booking a room on the same date. They could ignore what the availability checker says.
Nazeer AhamedNazeer Ahamed
Here is the trigger for avoiding dupes in leads. actually it checks email id in existing records, in this way you can try with date and room name for your need.

you can get this sample trigger in cook book  as well. hope this  helps !!!
StormConsultingStormConsulting
That looks like it would do the job. Where does the trigger code go?

Thanks a lot for the help!
Nazeer AhamedNazeer Ahamed
You have to put your trigger code on App Setup - Create - <<Your Object>> - Trigger.

Your Object - is where room details are stored.
StormConsultingStormConsulting
Ok, I went into my Booking object, there is a Triggers section, but there is no New button. Do triggers need enabling somewhere?

I'm using the Enterprise Edition.
Nazeer AhamedNazeer Ahamed
You can not create Trigger directly in production org, use your sand box (Apex) and deploy it.
StormConsultingStormConsulting
Ok, I have written my trigger in my Development Edition. Now I want to put this trigger on my Enterprise Edition. How can this be done?