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
nilesh walkenilesh walke 

wann test class for it

 public static void ForAge(List<contact> con5){
        for(Contact c:con5){
            Integer days=c.Birthdate.daysBetween(Date.today());
            c.Age__c=Integer.valueOf(days/365);
        }
    }   
Best Answer chosen by nilesh walke
Suraj Tripathi 47Suraj Tripathi 47

Hi Nilesh,
Please find The solution.

@isTest
public class ForAgeData{
    
   @testSetup static void ForAgeTest(){
       List<Contact> conList=new List<Contact>();
        Contact con=new Contact();
        con.LastName='Test';
        con.Birthdate=Date.today()+1;
       
       Contact conn=new Contact();
       conn.LastName='Test2';
       conn.Birthdate=Date.today()+5;
       conList.add(con);
       conList.add(conn);
       insert conList;
       test.startTest();
       ForAgeData.ForAge(conList);
       test.stopTest();
    }
}

Please mark it as the Best Answer so that other people would take references from it
Thank you

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi Nilesh,
Please find The solution.

@isTest
public class ForAgeData{
    
   @testSetup static void ForAgeTest(){
       List<Contact> conList=new List<Contact>();
        Contact con=new Contact();
        con.LastName='Test';
        con.Birthdate=Date.today()+1;
       
       Contact conn=new Contact();
       conn.LastName='Test2';
       conn.Birthdate=Date.today()+5;
       conList.add(con);
       conList.add(conn);
       insert conList;
       test.startTest();
       ForAgeData.ForAge(conList);
       test.stopTest();
    }
}

Please mark it as the Best Answer so that other people would take references from it
Thank you
This was selected as the best answer
CharuDuttCharuDutt
Hii Nilesh Walke
Try Below Code
@isTest
public class unitest {
  @isTest
    public static void unittest(){
   
     list<Contact> lstCon = new list<Contact>();
        for(integer i=0;i<5;i++){
            Contact Con =new Contact();
            Con.LastName = 'Test '+i;
            Con.Birthdate = Date.newInstance(1996, 04, 17);

            lstCon.add(Con);
            

        }
        
       
        insert lstCon;
        test2.ForAge(lstCon);
    }

}
Please Mark It As Best Answer If It Helps
Thank You!