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
AsitAsit 

Help with the Test Class

Hello,

 

I am a novice developer. It would be really helpful if anyone can help me with the Test Class.

I am unable to reach the required coverage!!

 

 

my apex class---

 

 

public class callReportCloneButton
{

 

/*-- All the required declarations */


public callReportCloneButton(ApexPages.StandardController controller)
{
accid= Apexpages.currentpage().getParameters().get('baId');
HCPid= Apexpages.currentpage().getParameters().get('cont');
dateTym= Apexpages.currentpage().getParameters().get('dt');
crID = Apexpages.currentpage().getParameters().get('crID');

getContactDetails();
}


//Returning The List Of HCP details related to the particular Bussiness Account for the respective clone button clicked.

public void getContactDetails()
{

listAccnt=[SELECT Id,FirstName,LastName,Job_Title__c,phone,Primary_Customer__c,Primary_Customer__r.name,BA_Address__c,X1st_Specialty__c FROM Contact WHERE Primary_Customer__c=:accid ORDER BY Job_Title__c] ;

hcpRecList=new List<hcpRecordClass>();

for (Contact a:listAccnt){
hcpRecordClass hrc=new hcpRecordClass();
hrc.cId = a.Id;
hrc.cFirstName = a.FirstName;
hrc.cLastName = a.LastName;
hrc.jobTitle = a.Job_Title__c;
hrc.cphn = a.phone;
hrc.pAccount = a.Primary_Customer__r.name;
hrc.cAddress = a.BA_Address__c;
hrc.primarySpclty = a.X1st_Specialty__c;
String cmpstr = String.valueOf(hrc.cId).substring(0,15);

if (cmpstr.trim() == HCPid.trim()){
hrc.blnHCPSelected = true;
}else{
hrc.blnHCPSelected = false;
}
hcpRecList.add(hrc);

}

}

//Create new HCP and create Event for the list of selected HCPs.

public PageReference insertHCP()
{
list<Account> instacc = new list<Account>();
list<Event> evntlist = new list<Event>();
Set<id> accids = new Set<id>();
Set<id> idsss = new Set<id>();


//Creating a Temporary List of Inner Class type to capture the selection among present list of HCPs.

hcpRecTemp=new List<hcpRecordClass>();
List<Event> evtList=new List<Event>();
for (hcpRecordClass hr:hcpRecList){

String cmpstr = String.valueOf(hr.cId).substring(0,15);
if (hr.blnHCPSelected == true && cmpstr.trim() != HCPid.trim()){
Event e=new Event();
e.Type__c='Call';
e.Call_Type__c='Face To Face';
e.WhoId = hr.cId;
e.StartDateTime = DateTime.parse(dateTym);
e.EndDateTime = DateTime.parse(dateTym);
evtList.add(e);
}
if(hr.blnHCPSelected == false && cmpstr.trim() == HCPid.trim())
{
check = true;
}

}
insert evtList; // Creating Events for the list of selected HCPs.



listRecordTyp = [select id from RecordType where sobjectType='Account' and developerName='personaccount']; // Fetching the Person Account (Record Type) that needed to be added to the account


if (sel1 == true)
{
// Creating Person Account (HCP) as per the selection in the bottom of the VF Page
Account acc = new Account();
acc.firstname = fname1;
acc.lastname = lname1;
acc.Job_Title__pc= job1;
acc.Has_a_computer__pc = comp1;
acc.X1st_Specialty__pc = sjob1;
acc.phone = phone1;
acc.PersonHasOptedOutOfEmail = true;
acc.Primary_Customer__pc = string.valueof(accid);
acc.recordtypeid = listRecordTyp.get(0).id; // '012200000009w7B';
//insert acc;
instacc.add(acc);
}

if(sel2 == true)
{
Account acc = new Account();
acc.firstname = fname2;
acc.lastname = lname2;
acc.Job_Title__pc= job2;
acc.Has_a_computer__pc = comp2;
acc.X1st_Specialty__pc = sjob2;
acc.phone = phone2;
acc.PersonHasOptedOutOfEmail = true;
acc.Primary_Customer__pc = String.valueOf(accid);
acc.recordtypeid = listRecordTyp.get(0).id;
instacc.add(acc);
}

if(sel3 == true)
{
Account acc = new Account();
acc.firstname = fname3;
acc.lastname = lname3;
acc.Job_Title__pc= job3;
acc.Has_a_computer__pc = comp3;
acc.X1st_Specialty__pc = sjob3;
acc.phone = phone3;
acc.PersonHasOptedOutOfEmail = true;
acc.Primary_Customer__pc = String.valueOf(accid);
acc.recordtypeid = listRecordTyp.get(0).id;
instacc.add(acc);
}
// Author: Asit Mishra
// @ Mahindra Satyam
//Creating Event for each of the added HCPs above
if(instacc.size()>0)
{
insert instacc;
for(account ac:instacc)
{
accids.add(ac.id);
}
if(accids.size()>0)
{
accList = [SELECT personContactId FROM Account WHERE id in: accids];
if(accList.size()>0)
{
for(account tempacc:accList)
{
Event e=new Event();
e.Type__c='Call';
e.Call_Type__c='Face To Face';
e.WhoId = tempacc.personContactId;
e.StartDateTime = DateTime.parse(dateTym);
e.EndDateTime = DateTime.parse(dateTym);
evntlist.add(e);
}
insert evntlist;
}
}
}


if(check == true) // Deleting Call Report of the dafault HCP is unselected.
{
set<id> eveids = new set<id>();
list<Call_Report__c> ccc =[select id from Call_Report__c where id =:crID];
if(ccc.size()>0)
{
for(Call_Report__c calobj:ccc)
{
eveids.add(calobj.id);
}

delete ccc;
}
if(eveids.size()>0)
{
List<Event> delevnt = [SELECT Id FROM Event WHERE Call_Report_Id__c =:eveids];
if(delevnt.size()>0)
delete delevnt;
}

}

datetime dt = datetime.parse(dateTym);
String doy = String.valueOf(dt.dayOfYear());
String yr = dateTym.substring(6,10);
PageReference reference=new PageReference('/00U/c?md0='+yr+'&md3='+doy);
reference.setRedirect(true);
return reference;
}

public Contact ct{
get{
if (ct == null) {
ct = new Contact ();
}
return ct ;
}
set;

}
public Call_Report__c cr {
get{
if (cr == null) {
cr = new Call_Report__c();
}
return cr ;
}
set;
}

// Inner Classes
public class hcpRecordClass {
public String cId {get;set;}
public boolean blnHCPSelected {get;set;}
public String cFirstName {get;set;}
public String cLastName {get;set;}
public String jobTitle {get;set;}
public String cphn {get;set;}
public String pAccount {get;set;}
public String cAddress {get;set;}
public String primarySpclty {get;set;}
}

}