You need to sign in to do that
Don't have an account?

Help writing test method
I'm completely new to Apex Code and OOP in general. I have written two simple, and probably poorly formed, triggers to update/clear some fields based on certain criteria. The triggers are working as expected in the sandbox but I cannot deploy without test methods. Any help/assisstance would be greatly appreciated.
I've looked at a few other threads about test methods but cannot for the life of me wrap my head around them.
Trigger #1:
trigger disagreeCompliance on CTM__c (before insert, before update) {
for(CTM__c ctm : trigger.new){
if(ctm.Disagree_with_Root_Cause_Checkbox__c != FALSE && ctm.Verified_By_1__c == null){
ctm.Verified_Process_Improvement_Step_1__c = null;
ctm.Verified_Responsible_Party_1__c = null;
ctm.Verified_Completion_Date_1__c = null;
}
if(ctm.Disagree_with_Root_Cause_Checkbox__c != FALSE && ctm.Verified_By_2__c == null){
ctm.Verified_Process_Improvement_Step_2__c = null;
ctm.Verified_Responsible_Party_2__c = null;
ctm.Verified_Completion_Date_2__c = null;
}
if(ctm.Disagree_with_Root_Cause_Checkbox__c != FALSE && ctm.Verified_By_3__c == null){
ctm.Verified_Process_Improvement_Step_3__c = null;
ctm.Verified_Responsible_Party_3__c = null;
ctm.Verified_Completion_Date_3__c = null;
}
if(ctm.Disagree_with_Root_Cause_Checkbox__c != FALSE && ctm.Verified_By_4__c == null){
ctm.Verified_Process_Improvement_Step_4__c = null;
ctm.Verified_Responsible_Party_4__c = null;
ctm.Verified_Completion_Date_4__c = null;
}
if(ctm.Disagree_with_Root_Cause_Checkbox__c != FALSE && ctm.Verified_By_5__c == null){
ctm.Verified_Process_Improvement_Step_5__c = null;
ctm.Verified_Responsible_Party_5__c = null;
ctm.Verified_Completion_Date_5__c = null;
}
}
}
Trigger #2:
trigger complianceVerified on CTM__c (before insert, before update) {
for(CTM__c ctm : trigger.new){
if(ctm.Process_Improvement_Step_1__c != null && ctm.Disagree_with_Root_Cause_Checkbox__c != TRUE){
ctm.Verified_Process_Improvement_Step_1__c = ctm.Process_Improvement_Step_1__c;
ctm.Verified_Responsible_Party_1__c = ctm.Process_Improvement_Responsible_Party_1__c;
ctm.Verified_Completion_Date_1__c = ctm.Process_Improvement_Completion_Date_1__c;
}
if(ctm.Process_Improvement_Step_2__c != null && ctm.Disagree_with_Root_Cause_Checkbox__c != TRUE){
ctm.Verified_Process_Improvement_Step_2__c = ctm.Process_Improvement_Step_2__c;
ctm.Verified_Responsible_Party_2__c = ctm.Process_Improvement_Responsible_Party_2__c;
ctm.Verified_Completion_Date_2__c = ctm.Process_Improvement_Completion_Date_2__c;
}
if(ctm.Process_Improvement_Step_3__c != null && ctm.Disagree_with_Root_Cause_Checkbox__c != TRUE){
ctm.Verified_Process_Improvement_Step_3__c = ctm.Process_Improvement_Step_3__c;
ctm.Verified_Responsible_Party_3__c = ctm.Process_Improvement_Responsible_Party_3__c;
ctm.Verified_Completion_Date_3__c = ctm.Process_Improvement_Completion_Date_3__c;
}
if(ctm.Process_Improvement_Step_4__c != null && ctm.Disagree_with_Root_Cause_Checkbox__c != TRUE){
ctm.Verified_Process_Improvement_Step_4__c = ctm.Process_Improvement_Step_4__c;
ctm.Verified_Responsible_Party_4__c = ctm.Process_Improvement_Responsible_Party_4__c;
ctm.Verified_Completion_Date_4__c = ctm.Process_Improvement_Completion_Date_4__c;
}
if(ctm.Process_Improvement_Step_5__c != null && ctm.Disagree_with_Root_Cause_Checkbox__c != TRUE){
ctm.Verified_Process_Improvement_Step_5__c = ctm.Process_Improvement_Step_5__c;
ctm.Verified_Responsible_Party_5__c = ctm.Process_Improvement_Responsible_Party_5__c;
ctm.Verified_Completion_Date_5__c = ctm.Process_Improvement_Completion_Date_5__c;
}
}
}
Here is your test class
I hope it will help you
All Answers
Here is your test class
I hope it will help you
Shashikant Sharma thank you so much!! That worked like a charm and now I have 100% coverage. You are truly a life saver. If you're every in central FL I'll buy you a round of beers. :smileyvery-happy:
I especially appreciate you commenting everything out like that.I aspire to be like you sir or madam.
Thanks again!!
-natty
Your welcome natty,
I am also here to learn, you can read some post in my blog to structure test class
http://forceschool.blogspot.com/search/label/Test%20Apex