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
chiranjib routchiranjib rout 

hii every one ,how could i write a test class for this trigger ,could any one provide me the test class codes for this trigger

trigger CTC_Update on Appraisal__c (after insert,before update ) {     List<appointment__c> AppList = New List<appointment__c>();     Set<Id> AppointIds = New Set<Id>();     For(Appraisal__c A : Trigger.New)     {         AppointIds.Add(A.ApplicantName__c);     }     List<appointment__c> AppointList = [Select Id,Current_CTC__c from appointment__c where id =: AppointIds];     For(Appraisal__c Aps : Trigger.New)     {         appointment__c A = new appointment__c();         For(appointment__c App : AppointList)         {             IF(Aps.ApplicantName__c == App.ID)             {                 A.Id = App.Id;                 IF(Aps.amount_of_Increment__c != 0 && Aps.amount_of_Increment__c != NULL)                 {                     A.Current_CTC__c = App.Current_CTC__c + Aps.amount_of_Increment__c ;                 }                 IF(Aps.Increment_Percentage__c != 0 && Aps.Increment_Percentage__c != NULL)                 {                     A.Current_CTC__c = App.Current_CTC__c + (App.Current_CTC__c * Aps.Increment_Percentage__c/100);                 }             }             AppList.Add(A);         }     }     IF(AppList != NULL)     {         Update AppList;     } }
Best Answer chosen by chiranjib rout
Dhanya NDhanya N
Hi Chiranjib,

Here is a sample of test class:
@isTest 
private class HelloWorldTestClass {
    static testMethod void validateHelloWorld() {
       appointment__c objAppointment = new appointment__c(Name='Test', Current_CTC__c=300000);
       insert objAppointment;
		
		Appraisal__c objAppraisal = new Appraisal__c(ApplicantName__c = objAppointment.Id, Increment_Percentage__c = 10, amount_of_Increment__c = 20000);
		insert objAppraisal;
      
    }
}

For more information regarding Test class, refer this link :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm

Thanks,
Dhanya

All Answers

Dhanya NDhanya N
Hi Chiranjib,

Here is a sample of test class:
@isTest 
private class HelloWorldTestClass {
    static testMethod void validateHelloWorld() {
       appointment__c objAppointment = new appointment__c(Name='Test', Current_CTC__c=300000);
       insert objAppointment;
		
		Appraisal__c objAppraisal = new Appraisal__c(ApplicantName__c = objAppointment.Id, Increment_Percentage__c = 10, amount_of_Increment__c = 20000);
		insert objAppraisal;
      
    }
}

For more information regarding Test class, refer this link :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm

Thanks,
Dhanya
This was selected as the best answer
chiranjib routchiranjib rout
thank so much Dhanya, please stay in touch.
Dhanya NDhanya N
Most Welcome Chiranjib.