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
sfdc development hintssfdc development hints 

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();
}