You need to sign in to do that
Don't have an account?

help in trigger issue
Hi all
this is my task.
actually i have to write a trigger to generate an error mesage the error message should be generated for following conditions
trigger error on Booking__c (after insert ,after update) { for(booking__c b:trigger.new) { Booking__c[] b1=[select id,To__c,From__c from Booking__c where From__c=:b.from__c and To__c =:b.to__c and room__c=:b.Room__c and Trainer__c=:b.trainer__c ]; booking__c[] b3=[select id,To__c,From__c from Booking__c where date__c=:b.date__c ]; for(Booking__c b4:b3) { for(Booking__c b5:b1) { if(b1.size()>1||b.from__c<b4.to__c) { b.addError('No more time slot to book this Appointment'); } } } } }
this is the trigger i have written actually the error message should be generated when the from time of the record i am going to insert should be less than the previous record to time and again if the same record is inserted twice again it should throw the error plz the trigger i have written is not working plz help me in this issue
you have a bunch of issues here, firstly you should look at removing any soql queries within a for loop. This is bad practice. I suggest you post what you want to do in psuedo code first, and then I can help you define your solution.