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
Isaac GomolkaIsaac Gomolka 

Test if Visualforce Page will save in extension test class

Hi everyone. I was wondering if there is a way to test if a visualforce page will save correctly. I have a VF page with an extension class. I am making a test class for that extension class. I want to test to see if after I do smaller tests and input all the required info for the VF page if it will save correctly ( aka all the required fields r working correctly).

So basically is there a way to test if the save method works and a VF saves successfully?

In case you need it, here is my test class:
@isTest 
public class EscalationPageExtensionTest 
{
    static testMethod void testMethod1() 
    {
    
        Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email');
        insert cas;
        

        Test.StartTest(); 
            ApexPages.StandardController sc = new ApexPages.StandardController(cas);
            EscalationPageExtension  testObj = new EscalationPageExtension(sc);
        
            testObj.picklist1 = 'true';
            testObj.picklist2 = 'true';
            testObj.picklist3 = 'true';
        	cas.Escalation_Users_Affected__c = '123';
        	cas.Escalation_Business_Functionality__c = 'Business Functionality I cant perform....';
        	
        	testObj.setDataIntegrity();
        	System.assertEquals(cas.Escalation_Data_Integrity__c, true);
        	
            testObj.setViableWorkaround();
            System.assertEquals(cas.Escalation_Viable_Workaround__c, true);
        
            testObj.setAppFunction();
        	System.assertEquals(cas.Escalation_Application_Functionality__c, true);
            
            List<SelectOption> lstOptions  = testObj.options;
            System.assert(lstOptions.size() > 0 );
        	
        	sc.save(); //This is where I want to know if I can test saving the VF page

        Test.StopTest();
    }
}

Thanks for your help in advanced!
Best Answer chosen by Isaac Gomolka
Amit Chaudhary 8Amit Chaudhary 8
You can try like below
@isTest 
public class EscalationPageExtensionTest 
{
    static testMethod void testEscalationApplicationFunctionality() 
    {
        Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email');
        insert cas;
		List<Case> lstCase;
		
        Test.StartTest(); 
            ApexPages.StandardController sc = new ApexPages.StandardController(cas);
            EscalationPageExtension  testObj = new EscalationPageExtension(sc);
        
            testObj.picklist1 = 'true';
            testObj.picklist2 = 'true';
            testObj.picklist3 = 'true';
            cas.Escalation_Users_Affected__c = '123';
            cas.Escalation_Business_Functionality__c = 'The Business Functionality I cant perform is....';
            
            List<SelectOption> lstOptions  = testObj.options;
            System.assert(lstOptions.size() > 0 );
			
            testObj.setAppFunction();
            sc.save();
            lstCase = [select id,Escalation_Application_Functionality__c from case where id =:cas.id ];
            System.assert(lstCase.size() > 0 );
            System.assertEquals(lstCase[0].Escalation_Application_Functionality__c , true ); 

            testObj.setDataIntegrity();
            sc.save();

            lstCase = [select id,Escalation_Data_Integrity__c from case where id =:cas.id ];
            System.assert(lstCase.size() > 0 );
            System.assertEquals(lstCase[0].Escalation_Data_Integrity__c , true ); 
			
            testObj.setViableWorkaround();
            sc.save();
            lstCase = [select id,Escalation_Viable_Workaround__c from case where id =:cas.id ];
            System.assert(lstCase.size() > 0 );
            System.assertEquals(lstCase[0].Escalation_Viable_Workaround__c , true ); 

		Test.StopTest();
    }	
}

Let us kno wif this will help you

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Hi Isaac Gomolka,

Try to query field like below

testObj.setAppFunction();
sc.save();
List<Case> lstCase = [select id,Escalation_Application_Functionality__c from case where id =:cas.id ];
System.assert(lstCase.size() > 0 );
System.assertEquals(lstCase[0].Escalation_Application_Functionality__c , true );


Let us know if this will help you
 
Amit Chaudhary 8Amit Chaudhary 8
You can try like below
@isTest 
public class EscalationPageExtensionTest 
{
    static testMethod void testEscalationApplicationFunctionality() 
    {
        Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email');
        insert cas;
		List<Case> lstCase;
		
        Test.StartTest(); 
            ApexPages.StandardController sc = new ApexPages.StandardController(cas);
            EscalationPageExtension  testObj = new EscalationPageExtension(sc);
        
            testObj.picklist1 = 'true';
            testObj.picklist2 = 'true';
            testObj.picklist3 = 'true';
            cas.Escalation_Users_Affected__c = '123';
            cas.Escalation_Business_Functionality__c = 'The Business Functionality I cant perform is....';
            
            List<SelectOption> lstOptions  = testObj.options;
            System.assert(lstOptions.size() > 0 );
			
            testObj.setAppFunction();
            sc.save();
            lstCase = [select id,Escalation_Application_Functionality__c from case where id =:cas.id ];
            System.assert(lstCase.size() > 0 );
            System.assertEquals(lstCase[0].Escalation_Application_Functionality__c , true ); 

            testObj.setDataIntegrity();
            sc.save();

            lstCase = [select id,Escalation_Data_Integrity__c from case where id =:cas.id ];
            System.assert(lstCase.size() > 0 );
            System.assertEquals(lstCase[0].Escalation_Data_Integrity__c , true ); 
			
            testObj.setViableWorkaround();
            sc.save();
            lstCase = [select id,Escalation_Viable_Workaround__c from case where id =:cas.id ];
            System.assert(lstCase.size() > 0 );
            System.assertEquals(lstCase[0].Escalation_Viable_Workaround__c , true ); 

		Test.StopTest();
    }	
}

Let us kno wif this will help you
This was selected as the best answer