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

Please help me in the code coverage of the below trigger
Trigger
trigger Intervieee on Interviewer__c (after Update) {
list<Candidates__c> updatedcand=new list<Candidates__c>();
set<ID> ChangedInter = new set<ID>();
Candidates__c can=new Candidates__c();
for(Interviewer__c i:trigger.new){
Interviewer__c invSet=Trigger.oldMap.get(i.Id);
system.debug('123456'+invSet.Mobile_no__c);
Candidates__c canList=[select Name,Phone_Number__c,Qualification__c,Rating__c,Review_comments__c,Result__c,Mobile_no__c from Candidates__c where Mobile_no__c =: invSet.Mobile_no__c];
if(invSet.Mobile_no__c==canList.Mobile_no__c){
canList.Name=i.CName__c;
canlist.Phone_Number__c=i.Phone_Number__c;
canlist.Qualification__c=i.Candidate_s_qualification__c;
canlist.Rating__c=i.Rating__c;
canlist.Review_comments__c=i.Review_Comments__c;
canlist.Result__c=i.Result__c;
canlist.Mobile_no__c=i.Mobile_no__c;
updatedcand.add(canList);
}
}
try{
system.debug('Before update');
update updatedcand;
system.debug('After update');
}
catch(Exception e){}
test class
@istest
public class Intervieeetest{
public static testmethod void testvalidate(){
test.starttest();
list<Candidates__c> candis=new list<Candidates__c>();
Candidates__c cand=new Candidates__c();
cand.Name='Testing';
cand.Qualification__c='BE';
cand.Review_comments__c='Keep it up';
cand.Rating__c='A';
cand.Result__c='Cleared';
cand.Mobile_no__c=0;
candis.add(cand);
insert candis;
Interviewer__c interview=new Interviewer__c ();
//interview.Name='Testing';
interview.Result__c='Pass';
insert interview;
test.stoptest();
}
}
trigger Intervieee on Interviewer__c (after Update) {
list<Candidates__c> updatedcand=new list<Candidates__c>();
set<ID> ChangedInter = new set<ID>();
Candidates__c can=new Candidates__c();
for(Interviewer__c i:trigger.new){
Interviewer__c invSet=Trigger.oldMap.get(i.Id);
system.debug('123456'+invSet.Mobile_no__c);
Candidates__c canList=[select Name,Phone_Number__c,Qualification__c,Rating__c,Review_comments__c,Result__c,Mobile_no__c from Candidates__c where Mobile_no__c =: invSet.Mobile_no__c];
if(invSet.Mobile_no__c==canList.Mobile_no__c){
canList.Name=i.CName__c;
canlist.Phone_Number__c=i.Phone_Number__c;
canlist.Qualification__c=i.Candidate_s_qualification__c;
canlist.Rating__c=i.Rating__c;
canlist.Review_comments__c=i.Review_Comments__c;
canlist.Result__c=i.Result__c;
canlist.Mobile_no__c=i.Mobile_no__c;
updatedcand.add(canList);
}
}
try{
system.debug('Before update');
update updatedcand;
system.debug('After update');
}
catch(Exception e){}
test class
@istest
public class Intervieeetest{
public static testmethod void testvalidate(){
test.starttest();
list<Candidates__c> candis=new list<Candidates__c>();
Candidates__c cand=new Candidates__c();
cand.Name='Testing';
cand.Qualification__c='BE';
cand.Review_comments__c='Keep it up';
cand.Rating__c='A';
cand.Result__c='Cleared';
cand.Mobile_no__c=0;
candis.add(cand);
insert candis;
Interviewer__c interview=new Interviewer__c ();
//interview.Name='Testing';
interview.Result__c='Pass';
insert interview;
test.stoptest();
}
}
use below test class
you are not update interview object after insert it in your test class so your trigger (after update) is not fire
let me inform if it helps you and mark you question solved if it helps you
thanks
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.Intervieee: line 15, column 1: []
make sure your
interview.Mobile_no__c = '0123456789';
and
cand.Mobile_no__c= '0123456789';
both are same
thanks
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
trigger candi on Candidates__c (after Insert) {
if(trigger.isinsert){
List<Interviewer__c> inns = new List<Interviewer__c>();
Interviewer__c i=new Interviewer__c();
for(Candidates__c c:Trigger.new){
i.CName__c=c.Name;
i.Phone_Number__c=c.Phone_Number__c;
i.Candidate_s_qualification__c=c.Qualification__c;
i.Mobile_no__c=c.Mobile_no__c;
inns.add(i);
}
try{
insert inns;
}
catch(Exception e){
system.debug(e);
}
}
}
and below test class give me 94% covager in my org with same trigger
I found below issue in your trigger. Please make your trigger as bulky.
1) SOQL inside for loop
Please try below code
Your test class should be like below Let us know if this will help you
After implimentation of your code,am getting the following error!
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: [].
Please help.