You need to sign in to do that
Don't have an account?
Hi , could anyone please help me in writting test class for the trigger below as follows
//Trigger on "enrollpeople" object which allows the field "Booked slots" to be incremented as the "EnrollPeople"is added and also verifying that "Booked slots" should not be greater than "Totalslots" //
trigger enrollcandidatetrigger on Enroll_Candidate__c(after delete, after insert, after update,after undelete)
{
Enroll_Candidate__c[] coursedetails;
if(Trigger.IsDelete)
coursedetails=Trigger.old;
else
coursedetails=Trigger.new;
Set<ID> CourseId= new set<ID>();
for(Enroll_Candidate__c candidates:coursedetails)
{
CourseId.add(candidates.Course_Details__c);
}
Map<ID,Course_Details__c> coursedetailsforcandidates=new Map<ID,Course_Details__c>([Select Id, Booked_Slots__c, Total_Slots__c, (Select Id from Enroll_Candidates__r ) from Course_Details__c where Id in:CourseId]);
for(Enroll_Candidate__c candidates:coursedetails)
{
Course_Details__c coursess = new Course_Details__c();
coursess = coursedetailsforcandidates.get(candidates.Course_Details__c);
if(coursess.Total_Slots__c >= coursess .Enroll_Candidates__r .size())
coursess.Booked_Slots__c=coursess .Enroll_Candidates__r .size();
else
candidates.addError('Booked seats should not exceed Total seats');
}
update coursedetailsforcandidates.values();
}