+ Start a Discussion
shravani milshravani mil 

unable to cover below method in my class

am unable to cover the below method in my test class.can any one help me ..

public static void updateChildResponses(map<Id,Lead> leadsMapNew,map<Id,Lead> leadsMapOld){
          list<Response__c> responses = new list<Response__c>();
          map<Id,Response__c> responseRecords = new map<Id,Response__c>();
          system.debug('test itt : '+leadsMapNew);
          system.debug('test it1 : '+leadsMapOld);
          for(Lead ld : leadsMapNew.values()){
          
           // if(ld.Status !=null && leadsMapOld !=null && leadsMapOld.get(ld.Id).Status != null && (((ld.Status)!=leadsMapOld.get(ld.Id).Status) || ((ld.OwnerId)!=leadsMapOld.get(ld.Id).OwnerId) || ((ld.Reason__c)!=leadsMapOld.get(ld.Id).Reason__c))){ //KP Added Reason 
           
           if(ld.Status !=null && leadsMapOld !=null && leadsMapOld.get(ld.Id) != null &&

    leadsMapOld.get(ld.Id).Status != null &&

    (((ld.Status)!=leadsMapOld.get(ld.Id).Status) ||

    ((ld.OwnerId)!=leadsMapOld.get(ld.Id).OwnerId) ||

    ((ld.Reason__c)!=leadsMapOld.get(ld.Id).Reason__c))){

   

           
           
               for(Response__c resp :[Select OwnerId, Status__c, Status_Date__c,Lead__c,Reason_LAI__c,Sales_Accepted__c, Sales_Accepted_Date__c,(Select OwnerId, Status__c, Status_Date__c,Lead__c, Reason_LAI__c,Sales_Accepted__c, Sales_Accepted_Date__c From  Related_Responses__r),Id From Response__c where Lead__c IN : leadsMapNew.keySet()]){ // Added Sales Accepted field
            responseRecords.put(resp.Id,resp);
          }
            }
          }
          if(responseRecords.size() > 0){
            
            for(Response__c resp : responseRecords.values()){
            System.debug('resp:::'+resp);
              if(leadsMapNew.containsKey(resp.Lead__c)){
                String status = leadsMapNew.get(resp.Lead__c).Status;
                String reason = leadsMapNew.get(resp.Lead__c).Reason__c;
                Date SalesAcceptedDate = leadsMapNew.get(resp.Lead__c).Sales_Accepted_Date__c;
                for(Response__c childResp:resp.Related_Responses__r){
                  System.debug('resp:::inside inner loop'+resp);
                  System.debug('childResp:::'+childResp);
                  if(!responseRecords.containsKey(childResp.Id)){
                    if(SalesAcceptedDate <> null && childResp.Sales_Accepted__c == false)
                    {
                        childResp.Sales_Accepted__c = true;
                        childResp.Sales_Accepted_Date__c = SalesAcceptedDate;
                    }
                    childResp.Status__c = status;
                    childResp.Reason_LAI__c = reason;
                    childResp.Status_Date__c = System.today();
                    childResp.OwnerId = leadsMapNew.get(resp.Lead__c).OwnerId;
                    responses.add(childResp);
                  }
                }
                if(SalesAcceptedDate <> null && Resp.Sales_Accepted__c == false)
                {
                    resp.Sales_Accepted__c = true;
                    resp.Sales_Accepted_Date__c = SalesAcceptedDate;
                }
                resp.Status__c = status;
                resp.Reason_LAI__c = reason;
                resp.Status_Date__c = System.today();
                resp.OwnerId = leadsMapNew.get(resp.Lead__c).OwnerId; 
              }
              responses.add(resp);
              
            }
            System.debug('responses:::'+responses); 
            Database.update(responses);
          }
        }        
Amit Chaudhary 8Amit Chaudhary 8
I hope above method you are calling from Lead Trigger. Just perform one update in your test class.
shravani milshravani mil
yeah updated but still its not covering
Amit Chaudhary 8Amit Chaudhary 8
please post your lead trigger , helper class and test class code.