You need to sign in to do that
Don't have an account?
Ankit Dable
How to write test class for below custom controller class?
public class EmployeeRegistrationController
{
public String selectedTab{get; set;}
public EmpID__c EmpID{get;set;}
public EmployeeInfo__c EmpDetail{get; set;}
public EducationInfo__c EduDetail{get; set;}
public List<EducationInfo__c> listEducation {get; set;}
public TechnologyInfo__c TechDetail{get;set;}
public List<TechnologyInfo__c> listTechnology {get;set;}
public List<EducationInfo__c> listEduInsert {get; set;}
public List<TechnologyInfo__c> listTechInsert{get;set;}
public Boolean button{get;set;}
public Boolean btnSubmit{get;set;}
public Boolean btnSave{get;set;}
public EmployeeRegistrationController()
{
selectedTab='Employee';
EmpDetail=new EmployeeInfo__c();
listEducation=new List<EducationInfo__c>();
TechDetail=new TechnologyInfo__c();
listTechnology=new List<TechnologyInfo__c> ();
EmpID=new EmpID__c();
button=true;
btnSubmit=true;
btnSave=false;
}
public void goNext1()
{
selectedTab='Education';
}
public PageReference saveInfo()
{
if(EmpDetail.First_Name__c==null||EmpDetail.Last_Name__c==null||EmpDetail.Email__c==null)
{
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill Basic details: First Name, Last Name, Email ID');
ApexPages.addMessage(msg);
}
else
{
try
{
insert EmpDetail;
ID Eid=[select ID from EmployeeInfo__c where Email__c=:EmpDetail.Email__c limit 1].ID;
EmpID=new EmpID__c(Eid__c=Eid);
button=false;
btnSave=true;
}
catch(Exception e)
{
System.debug(e.getMessage());
}
}
return null;
}
public void goNext2()
{
selectedTab='Technology';
}
public PageReference addNewRow()
{
if(EmpID.Eid__c==null)
{
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the Basic detail First');
ApexPages.addMessage(msg);
}
else
{
EduDetail=new EducationInfo__c();
EduDetail.Employee__c=EmpID.Eid__c;
listEducation.add(EduDetail);
}
return null;
}
public PageReference saveEducation()
{
for (EducationInfo__c c:listEducation)
{
if(c.course__c==null)
{
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the details');
ApexPages.addMessage(msg);
}
else
{
try
{
upsert listEducation;
listEduInsert=[SELECT Name, course__c,From_Date__c,To_Date__c FROM EducationInfo__c WHERE Employee__c=:EmpID.Eid__c];
}
catch(Exception e)
{
System.debug(e.getMessage());
}
}
}
listEducation.clear();
return null;
}
public PageReference addNewRow2()
{
TechDetail=new TechnologyInfo__c();
TechDetail.Employee__c=EmpID.Eid__c;
listTechnology.add(TechDetail);
return null;
}
public PageReference saveTechnology()
{
for(TechnologyInfo__c t: listTechnology)
{
if(t.Skill__c==null)
{
System.debug(t.Skill__c);
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the details');
ApexPages.addMessage(msg);
System.debug(msg);
}
else
{
try
{
upsert listTechnology;
listTechInsert =[SELECT Name, Experience__c,Level__c,Skill__c FROM TechnologyInfo__c WHERE Employee__c=:EmpID.Eid__c];
btnSubmit=false;
}
catch(Exception e)
{
System.debug(e.getMessage());
}
}
}
listTechnology.clear();
return null;
}
public PageReference submit()
{
SentEmail.sentToAdmin(EmpID.Eid__c);
SentEmail.sentToUser(EmpID.Eid__c);
PageReference pageRefer=new PageReference('/apex/FinalPage');
pageRefer.setRedirect(true);
return pageRefer;
}
}
Can someone please suggest me?
{
public String selectedTab{get; set;}
public EmpID__c EmpID{get;set;}
public EmployeeInfo__c EmpDetail{get; set;}
public EducationInfo__c EduDetail{get; set;}
public List<EducationInfo__c> listEducation {get; set;}
public TechnologyInfo__c TechDetail{get;set;}
public List<TechnologyInfo__c> listTechnology {get;set;}
public List<EducationInfo__c> listEduInsert {get; set;}
public List<TechnologyInfo__c> listTechInsert{get;set;}
public Boolean button{get;set;}
public Boolean btnSubmit{get;set;}
public Boolean btnSave{get;set;}
public EmployeeRegistrationController()
{
selectedTab='Employee';
EmpDetail=new EmployeeInfo__c();
listEducation=new List<EducationInfo__c>();
TechDetail=new TechnologyInfo__c();
listTechnology=new List<TechnologyInfo__c> ();
EmpID=new EmpID__c();
button=true;
btnSubmit=true;
btnSave=false;
}
public void goNext1()
{
selectedTab='Education';
}
public PageReference saveInfo()
{
if(EmpDetail.First_Name__c==null||EmpDetail.Last_Name__c==null||EmpDetail.Email__c==null)
{
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill Basic details: First Name, Last Name, Email ID');
ApexPages.addMessage(msg);
}
else
{
try
{
insert EmpDetail;
ID Eid=[select ID from EmployeeInfo__c where Email__c=:EmpDetail.Email__c limit 1].ID;
EmpID=new EmpID__c(Eid__c=Eid);
button=false;
btnSave=true;
}
catch(Exception e)
{
System.debug(e.getMessage());
}
}
return null;
}
public void goNext2()
{
selectedTab='Technology';
}
public PageReference addNewRow()
{
if(EmpID.Eid__c==null)
{
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the Basic detail First');
ApexPages.addMessage(msg);
}
else
{
EduDetail=new EducationInfo__c();
EduDetail.Employee__c=EmpID.Eid__c;
listEducation.add(EduDetail);
}
return null;
}
public PageReference saveEducation()
{
for (EducationInfo__c c:listEducation)
{
if(c.course__c==null)
{
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the details');
ApexPages.addMessage(msg);
}
else
{
try
{
upsert listEducation;
listEduInsert=[SELECT Name, course__c,From_Date__c,To_Date__c FROM EducationInfo__c WHERE Employee__c=:EmpID.Eid__c];
}
catch(Exception e)
{
System.debug(e.getMessage());
}
}
}
listEducation.clear();
return null;
}
public PageReference addNewRow2()
{
TechDetail=new TechnologyInfo__c();
TechDetail.Employee__c=EmpID.Eid__c;
listTechnology.add(TechDetail);
return null;
}
public PageReference saveTechnology()
{
for(TechnologyInfo__c t: listTechnology)
{
if(t.Skill__c==null)
{
System.debug(t.Skill__c);
ApexPages.Message msg=new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the details');
ApexPages.addMessage(msg);
System.debug(msg);
}
else
{
try
{
upsert listTechnology;
listTechInsert =[SELECT Name, Experience__c,Level__c,Skill__c FROM TechnologyInfo__c WHERE Employee__c=:EmpID.Eid__c];
btnSubmit=false;
}
catch(Exception e)
{
System.debug(e.getMessage());
}
}
}
listTechnology.clear();
return null;
}
public PageReference submit()
{
SentEmail.sentToAdmin(EmpID.Eid__c);
SentEmail.sentToUser(EmpID.Eid__c);
PageReference pageRefer=new PageReference('/apex/FinalPage');
pageRefer.setRedirect(true);
return pageRefer;
}
}
Can someone please suggest me?