You need to sign in to do that
Don't have an account?
Rajendra Shukla 22
hy i m trying to get 100 code coverage for the controller class not getting for catch block please help
controller===>
public class actionFunctionController{
public Position__c poc{get;set;}
public Boolean show{get;set;}
public Boolean showmessage{get;set;}
public actionFunctionController(ApexPages.StandardController stdController){
String pid = ((Position__c)stdcontroller.getRecord()).Id;
poc=[select id,name,Hire_By__c,Hiring_Manager__c,Job_Level__c,Functional_Area__c,Job_Description__c,Location__c,Max_Pay__c,
Min_Pay__c,Open_Date__c,Responsibilities__c,Travel_Required__c,Type__c,Status__c,Cancellation_Reason__c from Position__c where id=: pid];
show = false;
}
public PageReference Savefun(){
try{
if(poc.Status__c =='Cancelled' && poc.Cancellation_Reason__c == null){
showmessage = true;
return null;
}
else{
update poc;
showmessage=false;
PageReference newPage = new PageReference('https://ap2.salesforce.com/'+ApexPages.currentPage().getParameters().get('id'));
return newPage;
}
}
catch(Exception e){
ApexPages.addMessages(e);
return null;
}
return null;
}
public PageReference priorityChanged(){
if(poc.Status__c == 'Cancelled'){
show = true;
}
else{
show = false;
}
return null;
}
}
test class-->
@istest
public class Test_Action_contrller {
Static TestMethod void test_Method(){
Position__c poc = new Position__c();
poc.name = 'Hari';
poc.Hire_By__c = Date.newInstance(2017, 12,30);
poc.Status__c='Cancelled';
poc.Cancellation_Reason__c='Cancelled';
insert poc;
Position__c poc1 = new Position__c();
poc1.name = 'Hari';
poc1.Hire_By__c = Date.newInstance(2017, 12,30);
poc1.Status__c='Cancelled';
poc1.Cancellation_Reason__c='';
insert poc1;
Position__c poc2 = new Position__c(name = 'Hari',Hire_By__c = Date.newInstance(2017, 11,30),Status__c='Canceld',Cancellation_Reason__c='not need');
insert poc2;
ApexPages.StandardController sc= new ApexPages.StandardController(poc);
ApexPages.StandardController sc1= new ApexPages.StandardController(poc1);
ApexPages.StandardController sc2= new ApexPages.StandardController(poc2);
actionFunctionController afc=new actionFunctionController(sc);
actionFunctionController afc1=new actionFunctionController(sc1);
actionFunctionController afc2=new actionFunctionController(sc2);
Test.startTest();
afc.priorityChanged();
afc.Savefun();
afc1.Savefun();
afc2.priorityChanged();
afc2.Savefun();
Test.stopTest();
}
}
public class actionFunctionController{
public Position__c poc{get;set;}
public Boolean show{get;set;}
public Boolean showmessage{get;set;}
public actionFunctionController(ApexPages.StandardController stdController){
String pid = ((Position__c)stdcontroller.getRecord()).Id;
poc=[select id,name,Hire_By__c,Hiring_Manager__c,Job_Level__c,Functional_Area__c,Job_Description__c,Location__c,Max_Pay__c,
Min_Pay__c,Open_Date__c,Responsibilities__c,Travel_Required__c,Type__c,Status__c,Cancellation_Reason__c from Position__c where id=: pid];
show = false;
}
public PageReference Savefun(){
try{
if(poc.Status__c =='Cancelled' && poc.Cancellation_Reason__c == null){
showmessage = true;
return null;
}
else{
update poc;
showmessage=false;
PageReference newPage = new PageReference('https://ap2.salesforce.com/'+ApexPages.currentPage().getParameters().get('id'));
return newPage;
}
}
catch(Exception e){
ApexPages.addMessages(e);
return null;
}
return null;
}
public PageReference priorityChanged(){
if(poc.Status__c == 'Cancelled'){
show = true;
}
else{
show = false;
}
return null;
}
}
test class-->
@istest
public class Test_Action_contrller {
Static TestMethod void test_Method(){
Position__c poc = new Position__c();
poc.name = 'Hari';
poc.Hire_By__c = Date.newInstance(2017, 12,30);
poc.Status__c='Cancelled';
poc.Cancellation_Reason__c='Cancelled';
insert poc;
Position__c poc1 = new Position__c();
poc1.name = 'Hari';
poc1.Hire_By__c = Date.newInstance(2017, 12,30);
poc1.Status__c='Cancelled';
poc1.Cancellation_Reason__c='';
insert poc1;
Position__c poc2 = new Position__c(name = 'Hari',Hire_By__c = Date.newInstance(2017, 11,30),Status__c='Canceld',Cancellation_Reason__c='not need');
insert poc2;
ApexPages.StandardController sc= new ApexPages.StandardController(poc);
ApexPages.StandardController sc1= new ApexPages.StandardController(poc1);
ApexPages.StandardController sc2= new ApexPages.StandardController(poc2);
actionFunctionController afc=new actionFunctionController(sc);
actionFunctionController afc1=new actionFunctionController(sc1);
actionFunctionController afc2=new actionFunctionController(sc2);
Test.startTest();
afc.priorityChanged();
afc.Savefun();
afc1.Savefun();
afc2.priorityChanged();
afc2.Savefun();
Test.stopTest();
}
}
What is the code coverage now ?
Regards ,
Harish.R.
catch(Exception e){
ApexPages.addMessages(e);
return null;
}