+ Start a Discussion
H 007H 007 

Hi I need Test class for the following code..

public class UpdateMinDateHandler {
    
    Public static Boolean firstcall=false; // Stop the Recursive Calling
    Public static void triggerCall(List<Cus_Project__c> newRecordList){
        Set<Id> OrderId= new Set<Id>();
    List<Cus_Order__c> orderlist= new List<Cus_Order__c>();
    for(Cus_Project__c proj: newRecordList){
        OrderId.add(proj.Cus_Order__c);
    }   
    List<AggregateResult> resultlist= [SELECT Cus_Order__c, Min(Start__c)mindate, Max(End__c)maxdate FROM Cus_Project__c 
                                      where Cus_Order__c IN: OrderId group by Cus_Order__c ];
    List<Cus_Order__c> Updatedata=new  List<Cus_Order__c>();
    system.debug(resultlist);
    for(AggregateResult result:resultlist )
    {
      Updatedata.add(new  Cus_Order__c(Id = (Id)result.get('Cus_Order__c'),
                                      Order_Start_Date__c=(date)result.get('mindate'),
                                      Order_End_Date__c=(date)result.get('maxdate')));
     }
    update Updatedata;
    }

}
Best Answer chosen by H 007
H 007H 007
Hi Ankaiah  
Thank You for your reply but while runing this code follwoing error has been shown. Can you please help me..
 User-added image
 
 

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Harsh,

try with below code.
@isTest
public class UpdateMinDateHandlerTest {
public static testmethod void optyprojectTest(){

  //insert the required fields
    Cus_Order__c co = new Cus_Order__c ();
    co.Name = 'test';
    co.Name='test1';
    co.Order_Start_Date__c = System.today();
	co.Order_End_Date__c = System.today()+7;
   insert co;
  //insert the required fields
        Cus_Project__c  p1=new Cus_Project__c ();
        p1.Name='test';

   insert p1;
    
}
}

If this helps, Please mark it as best answer.

Thanks!!
H 007H 007
Hi Ankaiah  
Thank You for your reply but while runing this code follwoing error has been shown. Can you please help me..
 User-added image
 
 
This was selected as the best answer
AnkaiahAnkaiah (Salesforce Developers) 
Hi Harsh,

May i know, what is the error?

Can you check the updateprojecthandler.firstcall

Thanks!!