1

I've written apex class which is call from trigger , and now try to write test class but it not showing any code coverage Here is my apex class due to size limitation i'm unable to put my test class here

public class OptyCreationForDispFootPres
{   public static void createopty(List<Patient_Services__c> PSlist, map<id,Patient_Services__c> oldPSMap)
set<string> PatientID= new set<string>();
        List<Patient_Services__c> psnewlist = new List<Patient_Services__c>();List<Rate_Card__c> rcardnewlist =new List<Rate_Card__c>();
        List<sked__Job__c> joblist=new List<sked__Job__c>();
        List<sked__Job__c> joblistnw=new List<sked__Job__c>();
        Set<OpportunityLineItem> olilist=new Set<OpportunityLineItem>();
        List<OpportunityLineItem> olilist1=new List<OpportunityLineItem>(); 
        List<Opportunity> oplist=new List<Opportunity>();
        List<Account> accname = new List<Account>();
        Integer extid;
        String RecNamePodwP,RecNameAudwP,RecNameDiteticscwP,RecNameDivTrpwP,RecNameMntHlthwP,RecNameOccTrpwP,RecNameOptmwP,RecNamePhytrpwP,RecNamePhyTrpExClswP,RecNameRegNrsewP,RecNameSpchTrpwP;
        String myeffDate = date.today().format();
        Date Nxtoptycreationdate,Closedate;
        String BillableCycle,InvoiceSentby,InvoiceSentTo,Accntterms,RateCardtype;
        List<Patient_Services__c> psupdlist= new List<Patient_Services__c>();
        Map<String, Schema.SObjectType> sObjectMap = Schema.getGlobalDescribe() ;
        Map<String,Schema.RecordTypeInfo> recordType = sObjectMap.get('Opportunity').getDescribe().getRecordTypeInfosByName();
        ID RtIdPodwP,RtIdAudwP,RtIdDiteticscwP,RtIdDivTrpwP,RtIdMntHlthwP,RtIdOccTrpwP,RtIdOptmwP,RtIdPhytrpwP,RtIdPhyTrpExClswP,RtIdRegNrsewP,RtIdSpchTrpwP;
        User vLstUserop = [select id from User where Opportunity_Owner__c=true and IsActive=true LIMIT 1];
        List<Opportunity> opty=[select Id,Opty_No__c from Opportunity order by CreatedDate DESC limit 1];


         for(Patient_Services__c PS :PSlist)
        {
            if(ps.Ready_for_Billing__c==true && ps.Dispensing_Footwear_F049__c==true && oldPSMap.get(ps.id).Dispensing_Footwear_F049__c ==false)

            {
                PatientID.add(ps.id);
            }

        }

        psnewlist = [select id,Medicare_Account__c,Emergency_Visit__c,DVA_Code__c,Patient_DVA_Number__c,Patient_Medicare_No__c,
        Podiatry_Services__c,Job_Start_Datew_otime__c,Dispensing_Footwear_F049__c,DVA_Account__c,Initial_Consultation__c,
        Subsequent_Consulation__c,RecordType.name,Patient__r.Medicare_Account__c,Patient__r.Medicare_Account__r.Name,
        Patient__r.DVA_Account__c,Patient__r.DVA_Account__r.Name,Who_to_Invoice__c,Patient_Service_Lunch__c,
        Patient_Service_Invoice_Duration__c,Job_allocation_count__c,Job_Invoice_Start__c,Job_Invoice_Finish__c,
        Lunch_Break_Duration_from_Job__c,Job_Billable__c,Job__c,Patient_Service_Invoice_Finish__c,Patient_Service_Invoice_Start__c,
        Job_Type__c,Resource_Name__c,Service_Type__c from Patient_Services__c where id in :PatientID ]; 


         if(PatientID.size()>0)
        {

        system.debug('++++++++++++++++++++++++++'+psnewlist.size());

            List<Rate_Card__c> ratecardlist = new List<Rate_Card__c>();

            ratecardlist=[Select id,Next_Opportunity_Creation_Date__c,Which_Rate_to_use_withpatients__c,Footwear_Dispensed__c,
            Emergency_Visit__c,PricebookEntryId__c,Job_Type__c,Assessment__c,Travel__c,Report__c,Treatment_Rate__c,Menu_Review__c,
            Hourly_Rate__c,Account_Name__c,Other__c,Next_Billable_Date__c,Opportunity_Creation_Frequency__c,Invoice_sent_by__c,Invoice_sent_to__c,Account_Terms__c,
            Rate_Card_Type__c from Rate_Card__c where Account_Name__c='Department of Veteran Affairs'];

               // String DVAaccId = pslines.Patient__r.DVA_Account__c;
               //  String DVAaccName = pslines.Patient__r.DVA_Account__r.Name;


            for(Patient_Services__c pslines : psnewlist)
            {   for(Rate_Card__c rcard : ratecardlist)
                {
                if(rcard.Job_Type__c ==pslines.Job_Type__c && rcard.Rate_Card_Type__c == pslines.Service_Type__c)
                rcardnewlist.add(rcard);
                }
            }

            if(rcardnewlist.size()>0)
            {

            system.debug('******************'+rcardnewlist.size());

                for(Patient_Services__c pslines : psnewlist)
                {
                System.debug('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'+pslines.RecordType.name);
                     if(pslines.RecordType.name =='Podiatry')
                    {
                        RtIdPodwP = recordType.get('Podiatry with Patients').getRecordTypeId();
                        RecNamePodwP=recordType.get('Podiatry with Patients').getName();

                        System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!'+pslines.RecordType.name);
                   }
                 else if(pslines.RecordType.name =='Audiology')
                         {
                            RtIdAudwP = recordType.get('Audiology with Patients').getRecordTypeId();
                            RecNameAudwP=recordType.get('Audiology with Patients').getName();
                          }
                        else if(pslines.RecordType.name =='Dietetics')
                            {
                                RtIdDiteticscwP = recordType.get('Dietetics with Patients').getRecordTypeId();
                                RecNameDiteticscwP=recordType.get('Dietetics with Patients').getName();
                            }
                        else if(pslines.RecordType.name =='Diversional Therapy')
                            {
                                RtIdDivTrpwP = recordType.get('Diversional Therapy with Patients').getRecordTypeId();
                                RecNameDivTrpwP=recordType.get('Diversional Therapy with Patients').getName();
                            }
                        else if(pslines.RecordType.name =='Mental Health')
                        {
                            RtIdMntHlthwP = recordType.get('Mental Health with Patients').getRecordTypeId();
                            RecNameMntHlthwP = recordType.get('Mental Health with Patients').getName();
                        }
                        else if(pslines.RecordType.name =='Occupational Therapy')
                        {
                            RtIdOccTrpwP = recordType.get('Occupational Therapy with Patients').getRecordTypeId();
                            RecNameOccTrpwP=recordType.get('Occupational Therapy with Patients').getName();
                        }
                        else if(pslines.RecordType.name =='Optometry')
                        {
                            RtIdOptmwP = recordType.get('Optometry with Patients').getRecordTypeId();
                            RecNameOptmwP=recordType.get('Optometry with Patients').getName();
                        }
                        else if(pslines.RecordType.name =='Physiotherapy')
                        {
                            RtIdPhytrpwP = recordType.get('Physiotherapy with Patients').getRecordTypeId();
                            RecNamePhytrpwP=recordType.get('Physiotherapy with Patients').getName();
                        }
                        else if(pslines.RecordType.name =='Physiotherapy Exercise Classes')
                        {
                            RtIdPhyTrpExClswP = recordType.get('Physiotherapy Exercise Classes with Patients').getRecordTypeId();
                            RecNamePhyTrpExClswP=recordType.get('Physiotherapy Exercise Classes with Patients').getName();
                        }
                        else if(pslines.RecordType.name =='Registered Nurse')
                        {
                            RtIdRegNrsewP = recordType.get('Registered Nurse with Patients').getRecordTypeId();
                            RecNameRegNrsewP=recordType.get('Registered Nurse with Patients').getName();
                        }
                        else
                        {
                            RtIdSpchTrpwP = recordType.get('Speech Therapy with Patients').getRecordTypeId();
                            RecNameSpchTrpwP=recordType.get('Speech Therapy with Patients').getName();
                        }



                        for(Opportunity oppty:opty)
                        {
                            extid=Integer.valueOf(oppty.Opty_No__c)+1;
                        }


                         ///////////////////////////////////Code start here
                         Opportunity newopp =new Opportunity();
                         newopp.Optycreationbatch__c='DVA-WP-'+myeffDate+'-'+extid;


                             for(Rate_Card__c rc : rcardnewlist)
                        {
                                OpportunityLineItem oli = new OpportunityLineItem();
                                 oli.Opportunity =new Opportunity(Optycreationbatch__c=newopp.Optycreationbatch__c);
                                oli.PriceBookEntryId = rc.PricebookEntryId__c;
                                oli.Patient_Service__c=pslines.Id;
                                oli.Provider_Name__c=pslines.Resource_Name__c;
                                oli.Patient_Service_Invoice_Start__c=pslines.Patient_Service_Invoice_Start__c;
                                oli.Patient_Service_Invoice_Finish__c=pslines.Patient_Service_Invoice_Finish__c;
                                oli.Rate_Card__c=rc.Id;
                                oli.UnitPrice = rc.Hourly_Rate__c;
                                oli.Quantity = pslines.Job_allocation_count__c;
                                oli.Patient_Service_Lunch__c=pslines.Patient_Service_Lunch__c;
                                oli.Invoice_Start__c=pslines.Job_Invoice_Start__c;
                                oli.Invoice_Finish__c=pslines.Job_Invoice_Finish__c;
                                oli.Lunch_Break_Duration_from_Job__c=pslines.Lunch_Break_Duration_from_Job__c;
                                oli.DVA_Code__c=pslines.DVA_Code__c;
                                oli.AHP_Type__c=pslines.Podiatry_Services__c;

                                 if(pslines.Job_Billable__c ==true)
                                     {
                                          oli.Job_lkup__c=pslines.Job__c;
                                           oli.UnitPrice = rc.Footwear_Dispensed__c;
                                            oli.Quantity = pslines.Job_allocation_count__c;

                                     }
                                     else
                                         {
                                            oli.Job_lkup__c=pslines.Job__c;
                                            oli.Quantity = pslines.Job_Invoice_Duration__c; 
                                            oli.UnitPrice=0;
                                         }

                                    if( (oli.Quantity!=NULL) && (oli.PriceBookEntryId!=NULL))
                                        {
                                         olilist1.add(oli);
                                         psupdlist.add(pslines);
                                        }



                                newopp.OwnerId=vLstUserop.Id;
                                  newopp.stagename='To be reviewed';
                                  Nxtoptycreationdate=rc.Next_Opportunity_Creation_Date__c;
                                  Closedate=rc.Next_Billable_Date__c;
                                  BillableCycle=rc.Opportunity_Creation_Frequency__c;
                                  InvoiceSentby=rc.Invoice_sent_by__c;
                                  InvoiceSentTo=rc.Invoice_sent_to__c;
                                  Accntterms=rc.Account_Terms__c;
                                  RateCardtype=rc.Rate_Card_Type__c;

                                      newopp.DVA__c = true;
                                    newopp.AccountId=pslines.Patient__r.DVA_Account__c;

                                        System.debug('$$$$$$$$$$$$$$$$$$$$$$$$'+pslines.Patient__r.DVA_Account__r.Name);
                                        if(pslines.RecordType.name =='Podiatry')
                                        {
                                        newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNamePodwP + '-'+ Nxtoptycreationdate.format();
                                        newopp.RecordTypeId = recordType.get('Podiatry with Patients').getRecordTypeId();
                                        }
                                        else if(pslines.RecordType.name =='Audiology')
                                        {
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameAudwP + '-'+ Nxtoptycreationdate.format();
                                                 newopp.RecordTypeId=RtIdAudwP ;
                                         }
                                       else if(pslines.RecordType.name =='Dietetics')
                                        { 
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameDiteticscwP + '-'+ Nxtoptycreationdate.format();
                                                   newopp.RecordTypeId=RtIdDiteticscwP ;
                                         }
                                       else if(pslines.RecordType.name =='Diversional Therapy')
                                        {
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameDivTrpwP + '-'+ Nxtoptycreationdate.format();
                                                 newopp.RecordTypeId=RtIdDivTrpwP ;
                                         }
                                       else if(pslines.RecordType.name =='Mental Health')
                                        {
                                                newopp.RecordTypeId=RtIdMntHlthwP ;
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameMntHlthwP + '-'+ Nxtoptycreationdate.format();
                                        }
                                       else if(pslines.RecordType.name =='Occupational Therapy')
                                        {
                                                newopp.RecordTypeId=RtIdOccTrpwP ;
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameOccTrpwP + '-'+ Nxtoptycreationdate.format();
                                        }
                                       else if(pslines.RecordType.name =='Optometry')
                                        {
                                                newopp.RecordTypeId=RtIdOptmwP ;
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameOptmwP + '-'+ Nxtoptycreationdate.format();
                                         }
                                       else if(pslines.RecordType.name =='Physiotherapy')
                                        {
                                                newopp.RecordTypeId=RtIdPhytrpwP ;
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNamePhytrpwP + '-'+ Nxtoptycreationdate.format();
                                        }
                                       else if(pslines.RecordType.name =='Physiotherapy Exercise Classes')
                                        {
                                                newopp.RecordTypeId=RtIdPhyTrpExClswP ;
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNamePhyTrpExClswP + '-'+ Nxtoptycreationdate.format();
                                        }
                                       else if(pslines.RecordType.name =='Registered Nurse')
                                        {
                                                newopp.RecordTypeId=RtIdRegNrsewP ;
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameRegNrsewP + '-'+ Nxtoptycreationdate.format();
                                        }
                                       else if(pslines.RecordType.name =='Speech Pathology')
                                                {
                                                newopp.Name= pslines.Patient__r.DVA_Account__r.Name +'-' + RecNameSpchTrpwP + '-'+ Nxtoptycreationdate.format();
                                                  newopp.RecordTypeId=RtIdSpchTrpwP ; 
                                                 }

                                  newopp.closedate=Closedate;
                                  newopp.Billable_Cycle__c=BillableCycle;
                                  newopp.RateCard__c=rc.Id;
                                  newopp.Invoice_sent_by__c=InvoiceSentby;
                                  newopp.Invoice_sent_to__c=InvoiceSentTo;
                                  newopp.Date_From__c=pslines.Job_Start_Datew_otime__c;
                                  newopp.Patient_DVA_No__c = pslines.Patient_DVA_Number__c;
                                  newopp.Patient_Medicare_No__c = pslines.Patient_Medicare_No__c;
                                  newopp.AHP_Type__c= pslines.Podiatry_Services__c;
                                  newopp.Date_To__c=Nxtoptycreationdate;
                                  newopp.Service_Type__c=RateCardtype;
                                  oplist.add(newopp);


                            }
                }                               

                }   

            }        
      if(olilist1.size()>0 && oplist.size()>0)
               {
                 //  insert oplist;
                 //  insert olilist1;
             Database.SaveResult[] srList = Database.insert(oplist,false);
            Database.SaveResult[] srListlineitem = Database.insert(olilist1,false);  
            List<OpportunityLineItem> psidsfromlines=new List<OpportunityLineItem>();
            List<Patient_Services__c> psfinalupd= new List<Patient_Services__c>();
            List<Patient_Services__c> pswthsamejob = new List<Patient_Services__c>();
            List<sked__Job__c> jobfinalupd=new List<sked__Job__c>();
            Map<Id,Boolean> lineidssuccess=new Map<Id,Boolean>();
            List<Billing_Error_log__c> errorlog=new List<Billing_Error_log__c>();

             for (Database.SaveResult sr : srListlineitem) 
            {
                    if (!sr.isSuccess()) 
                    {
                      Billing_Error_log__c billlog = new Billing_Error_log__c();
                        // Operation failed, so get all errors                
                        for(Database.Error err : sr.getErrors()) 
                        {
                          billlog.Error_Message__c='The following error has occured while inserting Line items:'+err.getStatusCode() + ': ' + err.getMessage();
                          billlog.Error_Message__c=billlog.Error_Message__c+'Line item Fields that affected this error: ' + err.getFields();
                          billlog.Object_name__c='Opportunity Product';
                          errorlog.add(billlog);
                          //insert billlog;
                        }
                    }

                     if (sr.isSuccess()) 
                    {
                         lineidssuccess.put(sr.getId(),sr.isSuccess());
                    }
            }
              for (Database.SaveResult sr : srList) 
            {
               if (!sr.isSuccess()) 
                {
                Billing_Error_log__c billlog = new Billing_Error_log__c();
                    // Operation failed, so get all errors              
                    for(Database.Error err : sr.getErrors()) 
                    {

                      billlog.Error_Message__c='The following error has occured while inserting opportunity:'+err.getStatusCode() + ': ' + err.getMessage();
                      billlog.Error_Message__c=billlog.Error_Message__c+' Opportunity Fields that affected this error: ' + err.getFields();
                      billlog.Object_name__c='Opportunity';
                      //if(billlog.Id=='')
                      errorlog.add(billlog);
                      //insert billlog;
                    }   
                }                    

            } 
    system.debug('errorlog'+errorlog);
    if(errorlog.size()>0)
    {
    insert errorlog;
    }


            if(lineidssuccess.size()>0)
        {
                psidsfromlines=[select Id,Patient_Service__c from OpportunityLineItem where Id in: lineidssuccess.keySet()];
                List<sked__Job__c> jobvalues;
                List<Patient_Services__c> psvalues;
                Map<Id,Id> psidmap=new Map<Id,Id>();
                Map<Id,String> jobidmap=new Map<Id,String>();
                Integer counterjob=0;
                if(psidsfromlines.size()>0)
            {
                for(OpportunityLineItem oitem:psidsfromlines)
                    {
                        psidmap.put(oitem.Id,oitem.Patient_Service__c);
                    }

                try
                {
                      psvalues=[select Id, Added_to_Opty__c,Dispensing_Footwear_F049__c,Added_to_Opty_Dispensing_Footwear__c from Patient_Services__c where Id in :psidmap.values()];
                      system.debug('psvalues'+psvalues);
                          for(Patient_Services__c psupdt:psvalues)
                          {                 
                              psupdt.Added_to_Opty_Dispensing_Footwear__c=true;   
                              psfinalupd.add(psupdt);
                          }

                     if(psfinalupd.size()>0)
                    {
                     system.debug('psfinalupd'+psfinalupd);
                     update psfinalupd;
                     }
                }

                catch(DMLException e)
                {

                }
             }
        }
                }



    }

}

I've written test class but its not showing me code coverage. Due to size limitation i've written my test class below in answer

10
  • When you say "it is not showing code coverage", what exactly do you mean? Do you mean it is showing zero coverage (0) or do you mean it showing nothing? How are you checking code coverage anyways?
    – Mahmood
    Commented Jun 8, 2016 at 9:52
  • yes it showing 0 % code coverage
    – user29314
    Commented Jun 8, 2016 at 10:11
  • So, using the developer console, can you check line-by-line, which functions your test class is hitting and entering and which are not getting hit. I'm sorry but checking your code and test class will take huge time, and it will be better if you troubleshoot it yourself. Second, remove your test class from answer, it is not supposed to be there, put it in the code section in your question.
    – Mahmood
    Commented Jun 8, 2016 at 10:15
  • i include test code for new opportunity creation for apex class but when i check code coverage on dev consol its shwing in red lines means test line written in test class not taken into consideration.
    – user29314
    Commented Jun 8, 2016 at 10:18
  • yes it takes a large time to go through it for every one just told me that i've written test class is the correct way for that class or i've written in wrong way? i'm not sure about my test class
    – user29314
    Commented Jun 8, 2016 at 10:20

0

You must log in to answer this question.

Browse other questions tagged .