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
Tejender Mohan 9Tejender Mohan 9 

How verifying Trigger using test class which creates a new record in other object ? (how to get 100% code covarage)

Hello everyone,

For learnig purpose, I was creating a tigger with following functionality :

There is a canditate object with a checkbox "Active" ,
Trigger functionality is to create a new record in "Review" object whenever Active becomes True.

This is the code of Trigger :
trigger create_review_on_active on Candidate__c (after update) {
	//Creating a list of new record of Review__c
	list <Review__c> newrecord = new list<Review__c>();
	for (Candidate__c objacc :{
		if (objacc.active__c == True)
			Review__c objectr = new Review__c(); = 'Tejender Review'; // Just Creating record with fixed name for test Purpose. (Please suggest a way to use candidate name here.)
			newrecord .add(objectr);

	insert newrecord ;

To Test the Above code, Following  is the Testclass :
public class Candidate_Review {
    @isTest static void candidate_review_test(){
    Candidate__c necan = new Candidate__c(name = 'TMJ');
    insert necan;
        necan.Active__c = True;
		//At this point , i am not able to understand , how to Test whether the trigger is working fine or not ?

Question : 
As per my knoweldge, for test class it is good to create a sample data so that i have created "necan" in test class but i am not able to understand how should i
verify the new record of Review__c after Active__c becomes true and how should i get the proper code coverage.

Please suggest any solution so that can i verify this trigger using test class and
also please provide your expert comments about any good practice that should have been used in above codes as i am a beginer to APEX. :)

Thanks in advance :)

Best Answer chosen by Tejender Mohan 9
Tejender Mohan 9Tejender Mohan 9

I got the answer on stackexchange. Thanks :)

All Answers

Tejender Mohan 9Tejender Mohan 9

<head> How to verify the Trigger * <head>

I am also not able to find any option to update my question's headline,

I would be obliged If someone can help me with this too. :)

Tejender Mohan 9Tejender Mohan 9

I got the answer on stackexchange. Thanks :)

This was selected as the best answer