You need to sign in to do that
Don't have an account?

Test class for the follwing
Hi am new to salesforce please write the test class for the following controller.....
public class profileshortlists {
Id id = ApexPages.currentPage().getParameters().get('id');
public List<Profiles_Shortlisting__c> profilelists{get; set;}
public profileshortlists(ApexPages.StandardController controller) {
profilelists = new List<Profiles_Shortlisting__c>([select name,Candidate__c,Position__c,Candidate_Status__c,resume__c from Profiles_Shortlisting__c where id =: id]);
profilelists.add(new Profiles_Shortlisting__c(name='temp'));
}
public PageReference save() {
insert profilelists;
System.PageReference pageReference = new System.PageReference('/a02/o');
return PageReference;
//return new PageReference('/'+id);
}
}
public class profileshortlists {
Id id = ApexPages.currentPage().getParameters().get('id');
public List<Profiles_Shortlisting__c> profilelists{get; set;}
public profileshortlists(ApexPages.StandardController controller) {
profilelists = new List<Profiles_Shortlisting__c>([select name,Candidate__c,Position__c,Candidate_Status__c,resume__c from Profiles_Shortlisting__c where id =: id]);
profilelists.add(new Profiles_Shortlisting__c(name='temp'));
}
public PageReference save() {
insert profilelists;
System.PageReference pageReference = new System.PageReference('/a02/o');
return PageReference;
//return new PageReference('/'+id);
}
}
You can refer below code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
All Answers
You can refer below code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
In the 6th line instead of Position__c use correct API name for Position Object and same for Candidate Object.
And insert mandatory fields of both objects.
public class ProfileShortListsTest{
public static testmethod void testProfileListMethod ()
{
Job_Request__c pos = new Job_Request__c();
pos.Name = 'Job_Request';
pos.Job_Description__c = 'test';
pos.Hiring_Manager__c = 'test';
pos.Job_Max_Pay__c_c = 'test';
pos.Job_Min_Pay__c_c = 'test';
insert pos;
Candidate__c can = new Candidate__c();
can.Name = 'test';
can.Country__c = 'test';
can.Currently_Employed__c = 'test'
can.Name = 'test';
can.Country__c = 'test';
can.Currently_Employed__c = 'test'
insert can;
Profiles_Shortlisting__c profiles = new Profiles_Shortlisting__c();
profiles.name = 'Profile Name';
profiles.Candidate__c = can.Id;
profiles.Position__c = pos.Id;
profiles.Candidate_Status__c = 'Open';
profiles.resume__c = 'Test';
insert profiles;
PageReference pageRef = Page.Profileupdate ; //ProfileListPage with your vf page name
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id', profiles.Id);
profileshortlists pro = new profileshortlists();
pro.save();
}
}
@istest
public class ProfileShortListsTest{
public static testmethod void testProfileListMethod ()
{
Job_Request__c pos = new Job_Request__c();
pos.Name = 'Job_Request';
pos.Job_Description__c = 'test';
pos.Hiring_Manager__c = 'test';
pos.Max_Pay__c = 'test';
pos.Min_Pay__c = 'test';
insert pos;
Candidate__c can = new Candidate__c();
can.Name = 'test';
can.Country__c = 'test';
can.Currently_Employed__c = 'test';
insert can;
Profiles_Shortlisting__c profiles = new Profiles_Shortlisting__c();
profiles.name = 'Profile Name';
profiles.Candidate__c = can.Id;
profiles.Position__c = pos.Id;
profiles.Candidate_Status__c = 'Open';
profiles.resume__c = 'Test';
insert profiles;
PageReference pageRef = Page.Profileupdate ; //ProfileListPage with your vf page name
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id', profiles.Id);
profileshortlists pro = new profileshortlists();
pro.save();
}
}
pos.Min_Pay__c = 'test'; are number fields....
If Currently_Employed__c is checkbox, than update it with
@istest
public class ProfileShortListsTest{
public static testmethod void testProfileListMethod ()
{
Job_Request__c pos = new Job_Request__c();
pos.Name = 'Job_Request';
pos.Job_Description__c = 'test';
pos.Hiring_Manager__c = 'test';
pos.Max_Pay__c = '20000';
pos.Min_Pay__c = '5000';
insert pos;
Candidate__c can = new Candidate__c();
can.Name = 'test';
can.Country__c = 'test';
can.Currently_Employed__c = 'true';
insert can;
Profiles_Shortlisting__c profiles = new Profiles_Shortlisting__c();
profiles.name = 'Profile Name';
profiles.Candidate__c = can.Id;
profiles.Position__c = pos.Id;
profiles.Candidate_Status__c = 'Open';
// profiles.resume__c = 'Test';
insert profiles;
PageReference pageRef = Page.Profileupdate ; //ProfileListPage with your vf page name
Test.setCurrentPage(pageRef);
ApexPages.currentPage().getParameters().put('id', profiles.Id);
profileshortlists pro = new profileshortlists();
pro.save();
}
}