+ Start a Discussion
SapanaSapana 

Test Case for Trigger

Hi

 

I want to write a test case for a trigger which inserts "ENT_NMTC_Fund_Partnership__c"  record on insertion of  "ENT_NMTC_Fund__v" record

Could anyone help me in writing  a test case for this trigger since I am new to Apex Programming

Here is the trigger and its working fine

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

trigger ENT_Trigger_insert_NMTCPartnership on ENT_NMTC_Fund__c(after insert)
{
   
       for (ENT_NMTC_Fund__c fund:Trigger.new)
       {      
                  
              ENT_NMTC_Fund_Partnership__c partnership = new ENT_NMTC_Fund_Partnership__c();     
              partnership.Name =fund.Name ;  
               
                      
              partnership.NMTC_Fund__c= trigger.new[0].Id;          
              insert partnership;                                              
           }  
 
 
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SapanaSapana

I just had to add few lines and it worked fine

 

 

@isTest
   private class Testinsert_NMTCPartnership 
   {
   
       public static testMethod void ENT_Trigger_insert_NMTCPartnership() 
       {
           ENT_NMTC_Fund__c F = new ENT_NMTC_Fund__c(Name='Test');
           insert f;
           ENT_NMTC_Fund_Partnership__c fp = new ENT_NMTC_Fund_Partnership__c(Name='Test',NMTC_Fund__c=f.Id);
           
           insert fp;
   
                 
         
           
        }
   }

All Answers

@anilbathula@@anilbathula@

Hi

 

@isTest
public static testMethod void ENT_Trigger_insert_NMTCPartnership {

 

ENT_NMTC_Fund_Partnership__c partnership = new ENT_NMTC_Fund_Partnership__c(Name='Test',Add_other_Mandatory_fields);  

insert partnership;

}

 

 

Thanks

Anil.B

SapanaSapana

I just had to add few lines and it worked fine

 

 

@isTest
   private class Testinsert_NMTCPartnership 
   {
   
       public static testMethod void ENT_Trigger_insert_NMTCPartnership() 
       {
           ENT_NMTC_Fund__c F = new ENT_NMTC_Fund__c(Name='Test');
           insert f;
           ENT_NMTC_Fund_Partnership__c fp = new ENT_NMTC_Fund_Partnership__c(Name='Test',NMTC_Fund__c=f.Id);
           
           insert fp;
   
                 
         
           
        }
   }
This was selected as the best answer
SapanaSapana

Thanks Anil