You need to sign in to do that
Don't have an account?
Tejender 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 :
To Test the Above code, Following is the Testclass :
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 :)
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 : Trigger.new){ if (objacc.active__c == True) { Review__c objectr = new Review__c(); objectr.name = '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 :
@isTest public class Candidate_Review { @isTest static void candidate_review_test(){ Candidate__c necan = new Candidate__c(name = 'TMJ'); insert necan; Test.startTest(); necan.Active__c = True; //At this point , i am not able to understand , how to Test whether the trigger is working fine or not ? Test.stopTest(); } }
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 :)
Hi
I got the answer on stackexchange. Thanks :)
http://salesforce.stackexchange.com/questions/159631/how-to-verify-trigger-using-test-class-which-creates-a-new-record-in-other-objec/159634?noredirect=1#comment236811_159634
All Answers
<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. :)
Hi
I got the answer on stackexchange. Thanks :)
http://salesforce.stackexchange.com/questions/159631/how-to-verify-trigger-using-test-class-which-creates-a-new-record-in-other-objec/159634?noredirect=1#comment236811_159634