• tomspouse
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies

Hi,

How do i write a test case for the following trigger to cover 100% code coverage?

The one i have covers only 10%, am not sure which part of the code is not covered.

 

 

trigger AddInterview on Candidate_Requirement__c (after insert, after update) {
   
      
     for (Candidate_Requirement__c newInterview: Trigger.New) {
         if (newInterview.Status__c == 'Interview Stage' && newInterview.Candidates__c !=null && newInterview.Requirement__c != null) {
             String candR = newInterview.Id;
             List<Interview__c> intv = [select id,Candidates_submitted__c from Interview__c where Candidates_submitted__c = :candR ];
             
             if(intv.size() == 0){
                 String reqId = newInterview.Requirement__c;
                 List <Requirement__c> reqList = [select id, Contact__c from Requirement__c where id = :reqId ];
                 String candId =newInterview.Candidates__c;
                 List <Candidates__c> candList = [select id, Name from Candidates__c where id = :candId ];
                 String contId = reqList[0].Contact__c;
                 List <Contact> contList = [select id, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :contId ];
                 String mAddress= '';
                 if(!contList.isEmpty()){
                 
                     mAddress = contList[0].MAILINGSTREET +' '+ contList[0].MAILINGCITY+', '+ contList[0].MAILINGSTATE+' '+contList[0].MAILINGPOSTALCODE+' '+contList[0].MAILINGCOUNTRY;
                 }
                 if (!reqList.isEmpty() && !candList.isEmpty()){
                 Requirement__c req = reqList[0];
                 Candidates__c cand = candList[0];
                 Contact cont = contList[0];
                 

 

                 Interview__c interviews = new Interview__c(
                             Name = cand.Name, 
                             Candidates_submitted__c = newInterview.Id,
                             Client_Names__c = cont.Id,
                             Address_of_Interview__c = mAddress,
                             Candidate_Names__c = cand.Id,
                             Requirement_Names__c = req.Id);
                           
                           
                 insert interviews;
                 }
                 
             }
          }
      }
}

 

Test case:

 

@isTest
private class UpdateInterviewTest {
  
    static testMethod void testUpdateInterview() {
    
    
         //Insert contact record
         Contact con = new Contact(
                Lastname = 'test contact',
                MAILINGSTREET = 'street',
                MAILINGCITY = 'city',
                MAILINGSTATE = 'state',
                MAILINGPOSTALCODE = 'code',
                MAILINGCOUNTRY = 'country');
                
             insert con;
             con = [Select Id,Lastname, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :con.Id];
            
            //Insert Requiremnt Record
            Requirement__c req = new  Requirement__c(
                Contact__c = con.Id,
                Name = 'test req');
                
            insert req;
            req = [Select Id, Name,Contact__c from Requirement__c where Id = :req.Id];
            
            //Insert Candidates record
            Candidates__c cand = new Candidates__c (
                Name = 'test name',
                Candidate_Source__c = 'test picklist');
            insert cand;
            cand = [Select Id, Name,Candidate_Source__c from Candidates__c where Id = :cand.Id]; 
          
           //Insert Candidate submitted to requiremnt record whose status is not Interview Stage
           Candidate_Requirement__c cr = new Candidate_Requirement__c(
                Status__c = 'Offer Made',
                Candidates__c = cand.Id,
                Requirement__c = req.Id);
            
            insert cr;
            cr = [Select Id,Status__c,Candidates__c,Requirement__c from Candidate_Requirement__c where Id = :cr.Id];
            
          
                   
          Interview__c[] intv = [select Id ,Candidates_submitted__c from Interview__c where  Candidates_submitted__c= :cr.Id];
          if(intv.size() > 0)
          System.assertEquals(intv[0].Candidates_submitted__c, cr.Id); 
          
          }
         
     
   }

Hi,

How do i write a test case for the following trigger to cover 100% code coverage?

The one i have covers only 10%, am not sure which part of the code is not covered.

 

 

trigger AddInterview on Candidate_Requirement__c (after insert, after update) {
   
      
     for (Candidate_Requirement__c newInterview: Trigger.New) {
         if (newInterview.Status__c == 'Interview Stage' && newInterview.Candidates__c !=null && newInterview.Requirement__c != null) {
             String candR = newInterview.Id;
             List<Interview__c> intv = [select id,Candidates_submitted__c from Interview__c where Candidates_submitted__c = :candR ];
             
             if(intv.size() == 0){
                 String reqId = newInterview.Requirement__c;
                 List <Requirement__c> reqList = [select id, Contact__c from Requirement__c where id = :reqId ];
                 String candId =newInterview.Candidates__c;
                 List <Candidates__c> candList = [select id, Name from Candidates__c where id = :candId ];
                 String contId = reqList[0].Contact__c;
                 List <Contact> contList = [select id, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :contId ];
                 String mAddress= '';
                 if(!contList.isEmpty()){
                 
                     mAddress = contList[0].MAILINGSTREET +' '+ contList[0].MAILINGCITY+', '+ contList[0].MAILINGSTATE+' '+contList[0].MAILINGPOSTALCODE+' '+contList[0].MAILINGCOUNTRY;
                 }
                 if (!reqList.isEmpty() && !candList.isEmpty()){
                 Requirement__c req = reqList[0];
                 Candidates__c cand = candList[0];
                 Contact cont = contList[0];
                 

 

                 Interview__c interviews = new Interview__c(
                             Name = cand.Name, 
                             Candidates_submitted__c = newInterview.Id,
                             Client_Names__c = cont.Id,
                             Address_of_Interview__c = mAddress,
                             Candidate_Names__c = cand.Id,
                             Requirement_Names__c = req.Id);
                           
                           
                 insert interviews;
                 }
                 
             }
          }
      }
}

 

Test case:

 

@isTest
private class UpdateInterviewTest {
  
    static testMethod void testUpdateInterview() {
    
    
         //Insert contact record
         Contact con = new Contact(
                Lastname = 'test contact',
                MAILINGSTREET = 'street',
                MAILINGCITY = 'city',
                MAILINGSTATE = 'state',
                MAILINGPOSTALCODE = 'code',
                MAILINGCOUNTRY = 'country');
                
             insert con;
             con = [Select Id,Lastname, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :con.Id];
            
            //Insert Requiremnt Record
            Requirement__c req = new  Requirement__c(
                Contact__c = con.Id,
                Name = 'test req');
                
            insert req;
            req = [Select Id, Name,Contact__c from Requirement__c where Id = :req.Id];
            
            //Insert Candidates record
            Candidates__c cand = new Candidates__c (
                Name = 'test name',
                Candidate_Source__c = 'test picklist');
            insert cand;
            cand = [Select Id, Name,Candidate_Source__c from Candidates__c where Id = :cand.Id]; 
          
           //Insert Candidate submitted to requiremnt record whose status is not Interview Stage
           Candidate_Requirement__c cr = new Candidate_Requirement__c(
                Status__c = 'Offer Made',
                Candidates__c = cand.Id,
                Requirement__c = req.Id);
            
            insert cr;
            cr = [Select Id,Status__c,Candidates__c,Requirement__c from Candidate_Requirement__c where Id = :cr.Id];
            
          
                   
          Interview__c[] intv = [select Id ,Candidates_submitted__c from Interview__c where  Candidates_submitted__c= :cr.Id];
          if(intv.size() > 0)
          System.assertEquals(intv[0].Candidates_submitted__c, cr.Id); 
          
          }
         
     
   }

 

@isTest
private class UpdateInterviewTest {
 
    static testMethod void testUpdateInterview() {
    
    
         //Insert contact record
         Contact con = new Contact(
                Lastname = 'test contact',
                MAILINGSTREET = 'street',
                MAILINGCITY = 'city',
                MAILINGSTATE = 'state',
                MAILINGPOSTALCODE = 'code',
                MAILINGCOUNTRY = 'country');
                
             insert con;
             con = [Select Id,Lastname, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :con.Id];
            
            //Insert Requiremnt Record
            Requirement__c req = new  Requirement__c(
                Contact__c = con.Id,
                Name = 'test req');
                
            insert req;
            req = [Select Id, Name,Contact__c from Requirement__c where Id = :req.Id];
            
            //Insert Candidates record
            Candidates__c cand = new Candidates__c (
                Name = 'test name',
                Candidate_Source__c = 'test picklist');
            insert cand;
            cand = [Select Id, Name,Candidate_Source__c from Candidates__c where Id = :cand.Id];
          
           //Insert Candidate submitted to requiremnt record whose status is not Interview Stage
           Candidate_Requirement__c cr = new Candidate_Requirement__c(
                Status__c = 'Offer Made',
                Candidates__c = cand.Id,
                Requirement__c = req.Id);
            
            insert cr;
            cr = [Select Id,Status__c,Candidates__c,Requirement__c from Candidate_Requirement__c where Id = :cr.Id];
            
          
                   
          Interview__c[] intv = [select Id ,Candidates_submitted__c from Interview__c where  Candidates_submitted__c= :cr.Id];
          if(intv.size() > 0)
          System.assertEquals(intv[0].Candidates_submitted__c, cr.Id);
          
          }
         
     
   }

Hi good people,

I have a trigger & test case which has 100% Code Coverage Total % on sandbox but gives me the following error while trying to deploy it to production:

 

Failure Message: "System.DmlException: Update failed. First exception on row 0 with id a023000000EufXbAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddInterview: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.AddInterview: line 15, column 33: []", Failure...

 

Below is my trigger with its test case which is suppose to create new record to child object Interview once status on parent object Candidate submitted to requirements changes to 'Interview Stage'.

 

Trigger Code:

 

 

trigger AddInterview on Candidate_Requirement__c (after insert, after update) {
   
      
     for (Candidate_Requirement__c newInterview: Trigger.New) {
         if (newInterview.Status__c == 'Interview Stage' && newInterview.Candidates__c !=null && newInterview.Requirement__c != null) {
             String candR = newInterview.Id;
             List<Interview__c> intv = [select id,Candidates_submitted__c from Interview__c where Candidates_submitted__c = :candR ];
             
             if(intv.size() == 0){
                 String reqId = newInterview.Requirement__c;
                 Requirement__c req = [select id, Contact__c from Requirement__c where id = :reqId ];
                 String candId =newInterview.Candidates__c;
                 Candidates__c cand = [select id, Name from Candidates__c where id = :candId ];
                 String contId = req.Contact__c;
                 Contact cont = [select id, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :contId ];
              
                 String mAddress = cont.MAILINGSTREET +' '+ cont.MAILINGCITY+', '+ cont.MAILINGSTATE+' '+cont.MAILINGPOSTALCODE+' '+cont.MAILINGCOUNTRY;
                 
                 Interview__c interviews = new Interview__c(
                             Name = cand.Name, 
                             Candidates_submitted__c = newInterview.Id,
                             Client_Names__c = cont.Id,
                             Address_of_Interview__c = mAddress,
                             Candidate_Names__c = cand.Id,
                             Requirement_Names__c = req.Id);
                             
                 insert interviews;
             }
          }
      }
}



 

Test code;

 

@isTest
private class UpdateInterviewTest {
 
    static testMethod void testUpdateInterview() {
        
            
       for(Candidate_Requirement__c cr : [select id, status__c from Candidate_Requirement__c]){
            
                        
          if(cr.status__c != 'Interview Stage'){
                   
                   
                   cr.status__c='Interview Stage';
                   
                   update cr;
                   
                   
          Interview__c[] intv = [select Id ,Candidates_submitted__c from Interview__c where  Candidates_submitted__c= :cr.Id];
          if(intv.size() > 0)
          System.assertEquals(intv[0].Candidates_submitted__c, cr.Id);  
          }
    }
  }
 }

 

 

I am a very contented user of Maildrop, a super well written piece of technology that could easily be charged for!

 

We use a lot of custom objects, and regularly wish to attach emails to those objects.  You do cater for this, however, I find it necessary to copy the email address from the first email box, associated with 'Contacts' down to the box associated with 'Custom Objects'. 

 

I don't see any reason for not merging the two together,  in other words, just have one search box related to All objects, regardless of whether they are custom or not.

 

 

Simon,  I have been using your product Maildrop for some years and have had good success with it.  However you recently changed the manner in which attachments were added to Salesforce.  In the past, the attachment showed up on the actual object/contact etc, now it shows up on the actual email or activity.  I like the way you have done this, but we have become very used to the manner you used to do this.  Would there be a way that I could have the option to attach an attachment, both to the actual 'Object' or 'Contact', rather than nesting it under the email itself???

 

 

Hi,

How do i write a test case for the following trigger to cover 100% code coverage?

The one i have covers only 10%, am not sure which part of the code is not covered.

 

 

trigger AddInterview on Candidate_Requirement__c (after insert, after update) {
   
      
     for (Candidate_Requirement__c newInterview: Trigger.New) {
         if (newInterview.Status__c == 'Interview Stage' && newInterview.Candidates__c !=null && newInterview.Requirement__c != null) {
             String candR = newInterview.Id;
             List<Interview__c> intv = [select id,Candidates_submitted__c from Interview__c where Candidates_submitted__c = :candR ];
             
             if(intv.size() == 0){
                 String reqId = newInterview.Requirement__c;
                 List <Requirement__c> reqList = [select id, Contact__c from Requirement__c where id = :reqId ];
                 String candId =newInterview.Candidates__c;
                 List <Candidates__c> candList = [select id, Name from Candidates__c where id = :candId ];
                 String contId = reqList[0].Contact__c;
                 List <Contact> contList = [select id, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :contId ];
                 String mAddress= '';
                 if(!contList.isEmpty()){
                 
                     mAddress = contList[0].MAILINGSTREET +' '+ contList[0].MAILINGCITY+', '+ contList[0].MAILINGSTATE+' '+contList[0].MAILINGPOSTALCODE+' '+contList[0].MAILINGCOUNTRY;
                 }
                 if (!reqList.isEmpty() && !candList.isEmpty()){
                 Requirement__c req = reqList[0];
                 Candidates__c cand = candList[0];
                 Contact cont = contList[0];
                 

 

                 Interview__c interviews = new Interview__c(
                             Name = cand.Name, 
                             Candidates_submitted__c = newInterview.Id,
                             Client_Names__c = cont.Id,
                             Address_of_Interview__c = mAddress,
                             Candidate_Names__c = cand.Id,
                             Requirement_Names__c = req.Id);
                           
                           
                 insert interviews;
                 }
                 
             }
          }
      }
}

 

Test case:

 

@isTest
private class UpdateInterviewTest {
  
    static testMethod void testUpdateInterview() {
    
    
         //Insert contact record
         Contact con = new Contact(
                Lastname = 'test contact',
                MAILINGSTREET = 'street',
                MAILINGCITY = 'city',
                MAILINGSTATE = 'state',
                MAILINGPOSTALCODE = 'code',
                MAILINGCOUNTRY = 'country');
                
             insert con;
             con = [Select Id,Lastname, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :con.Id];
            
            //Insert Requiremnt Record
            Requirement__c req = new  Requirement__c(
                Contact__c = con.Id,
                Name = 'test req');
                
            insert req;
            req = [Select Id, Name,Contact__c from Requirement__c where Id = :req.Id];
            
            //Insert Candidates record
            Candidates__c cand = new Candidates__c (
                Name = 'test name',
                Candidate_Source__c = 'test picklist');
            insert cand;
            cand = [Select Id, Name,Candidate_Source__c from Candidates__c where Id = :cand.Id]; 
          
           //Insert Candidate submitted to requiremnt record whose status is not Interview Stage
           Candidate_Requirement__c cr = new Candidate_Requirement__c(
                Status__c = 'Offer Made',
                Candidates__c = cand.Id,
                Requirement__c = req.Id);
            
            insert cr;
            cr = [Select Id,Status__c,Candidates__c,Requirement__c from Candidate_Requirement__c where Id = :cr.Id];
            
          
                   
          Interview__c[] intv = [select Id ,Candidates_submitted__c from Interview__c where  Candidates_submitted__c= :cr.Id];
          if(intv.size() > 0)
          System.assertEquals(intv[0].Candidates_submitted__c, cr.Id); 
          
          }
         
     
   }

Hi good people,

I have a trigger & test case which has 100% Code Coverage Total % on sandbox but gives me the following error while trying to deploy it to production:

 

Failure Message: "System.DmlException: Update failed. First exception on row 0 with id a023000000EufXbAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddInterview: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.AddInterview: line 15, column 33: []", Failure...

 

Below is my trigger with its test case which is suppose to create new record to child object Interview once status on parent object Candidate submitted to requirements changes to 'Interview Stage'.

 

Trigger Code:

 

 

trigger AddInterview on Candidate_Requirement__c (after insert, after update) {
   
      
     for (Candidate_Requirement__c newInterview: Trigger.New) {
         if (newInterview.Status__c == 'Interview Stage' && newInterview.Candidates__c !=null && newInterview.Requirement__c != null) {
             String candR = newInterview.Id;
             List<Interview__c> intv = [select id,Candidates_submitted__c from Interview__c where Candidates_submitted__c = :candR ];
             
             if(intv.size() == 0){
                 String reqId = newInterview.Requirement__c;
                 Requirement__c req = [select id, Contact__c from Requirement__c where id = :reqId ];
                 String candId =newInterview.Candidates__c;
                 Candidates__c cand = [select id, Name from Candidates__c where id = :candId ];
                 String contId = req.Contact__c;
                 Contact cont = [select id, MAILINGSTREET,MAILINGCITY,MAILINGSTATE,MAILINGPOSTALCODE,MAILINGCOUNTRY from Contact where id = :contId ];
              
                 String mAddress = cont.MAILINGSTREET +' '+ cont.MAILINGCITY+', '+ cont.MAILINGSTATE+' '+cont.MAILINGPOSTALCODE+' '+cont.MAILINGCOUNTRY;
                 
                 Interview__c interviews = new Interview__c(
                             Name = cand.Name, 
                             Candidates_submitted__c = newInterview.Id,
                             Client_Names__c = cont.Id,
                             Address_of_Interview__c = mAddress,
                             Candidate_Names__c = cand.Id,
                             Requirement_Names__c = req.Id);
                             
                 insert interviews;
             }
          }
      }
}



 

Test code;

 

@isTest
private class UpdateInterviewTest {
 
    static testMethod void testUpdateInterview() {
        
            
       for(Candidate_Requirement__c cr : [select id, status__c from Candidate_Requirement__c]){
            
                        
          if(cr.status__c != 'Interview Stage'){
                   
                   
                   cr.status__c='Interview Stage';
                   
                   update cr;
                   
                   
          Interview__c[] intv = [select Id ,Candidates_submitted__c from Interview__c where  Candidates_submitted__c= :cr.Id];
          if(intv.size() > 0)
          System.assertEquals(intv[0].Candidates_submitted__c, cr.Id);  
          }
    }
  }
 }

 

 

I am a very contented user of Maildrop, a super well written piece of technology that could easily be charged for!

 

We use a lot of custom objects, and regularly wish to attach emails to those objects.  You do cater for this, however, I find it necessary to copy the email address from the first email box, associated with 'Contacts' down to the box associated with 'Custom Objects'. 

 

I don't see any reason for not merging the two together,  in other words, just have one search box related to All objects, regardless of whether they are custom or not.