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
P Kumar 243P Kumar 243 

Trigger For a doctor to not having more than 8 appointments in a day

I have a scenario where a dcotor cannot have more than 8 appointments in a day. I need to write a trigger on Appointment. I have three custom object Patient,Docator and appointment. Appointment have a lookup of both patient and doctor.

Amit M 3Amit M 3
  • I assume the trigger will be before insert/update
  • Find the doctor from the appointment record in the trigger.
  • Do a Aggregate Query on Appointment object, group by doctor, for the given day. Loop through the results to find out the existing number of appointment for the doctor. If it is equal to 8, then throw error, else continue.
I hope this makes sense.
P Kumar 243P Kumar 243

Hi Amit,

I am new to salesforce. Can you help me in writing the code.

Thanks

Amit M 3Amit M 3
Please go through Apex Developer Guide (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dev_guide.htm). You can also try trailhead modules (https://trailhead.salesforce.com/en/modules/apex_database) to learn apex programming.
P Kumar 243P Kumar 243

I am not able to do a Aggregate Query on Appointment object, group by doctor, for the given day. Loop through the results to find out the existing number of appointment for the doctor. If it is equal to 8, then throw error, else continue.

Can you please ellobrate this.It will be helpful for me.