function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
aklkkaklkk 

how to covered the trigger test class because i am facing a problem ? its my Code

hi,

i am faceing a probject for coverage a unit test code please help me ?

trigger on inforamtionManagement on informationManagement__c(After insert) {
    for(informationManagement__c infoobj:trigger.new){
    
    if(infoobj.canclae_Event__c== False && infoobj.Target_People__c=='Person'){
        Resitration_from__c rsfobj=new Resitration_from__c();
        rsfobj.Record_type='new';
        rsfobj.Account_Name=infoobj.lead_Name__c;
        rsfobj.start_date__c=infoobj.start_date__c;
        isnert(rsfobj);
    
    
    
    
    }
    
    
    
    }

}
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please try the below code.
 
@isTest
public class Test_InformationManagement {
    static testMethod void insertInformationManagement() {
        
        InformationManagement__c im = new InformationManagement__c();
        
        im.Name = "New";
        im.canclae_Event__c = false;
        im.Target_People__c = "Person";
        //Add other required fields 

        INSERT im;
        
    }
}

Also, You have DML inside for loop. You should never do a DML inside of a loop. Change your code to:
 
trigger on inforamtionManagement on informationManagement__c(After insert) {

    List<Resitration_from__c> rlst = new List<Resitration_from__c>();
    for(informationManagement__c infoobj:trigger.new){
    
    if(infoobj.canclae_Event__c== False && infoobj.Target_People__c=='Person'){
        Resitration_from__c rsfobj=new Resitration_from__c();
        rsfobj.Record_type='new';
        rsfobj.Account_Name=infoobj.lead_Name__c;
        rsfobj.start_date__c=infoobj.start_date__c;
        rlst.add(rsfobj);
    }
    }
    if(rlst.size()>0){
        INSERT rlst;
    }
}

Please refer to below links for more information:

https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers

http://www.sfdc99.com/2013/11/02/example-write-a-test-class-for-our-deduping-trigger/

http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
aklkkaklkk
hi Anash 
its working fine but when i going for (After delete) but its not good work