+ Start a Discussion

Test Class Help for VF Page

I have a VF page that we created that looks like this:


<apex:page standardController="Lead" extensions="TeamTrackFlag" sidebar="true">
  <apex:sectionHeader title="Edit Lead Record:"
  <apex:form >
    <apex:pageBlock title="Create TeamTrack Flag" id="thePageBlock"
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      <FONT COLOR="RED"><b>IMPORTANT: </b> Should a TeamTrack be created for this Opportunity?</FONT>
              <br /><br />
        <td width="200" align="center"><b>Create TeamTrack?</b></td>
        <td width="100" align="left"><apex:inputField value="{!Lead.Create_TeamTrack__c}" id="TTFlag"/></td>
        <td width="200" align="left"> Checked = YES<br />Unchecked = NO<br /></td>
        <br />
        <br />
        <B>PLEASE NOTE:</B>
        <BR />
        The system default is 'YES'. Your answer should only be 'NO' if you were notified by Recruitment Support about a TeamTrack that was manually created on your behalf.
        <apex:inputField value="{!Lead.ID}" rendered="false" />
        <apex:inputField value="{!Lead.Name}" rendered="false" />
        <apex:inputField value="{!Lead.Company}" rendered="false" />

The class is:


public class TeamTrackFlag{
    ApexPages.StandardController controller;
    Lead cntr;
        public TeamTrackFlag(ApexPages.StandardController con){
                controller = con;
                cntr= (Lead)controller.getRecord();
public PageReference save()
 {        controller.save();
         PageReference redirecturl = new PageReference('/lead/leadconvert.jsp?retURL=/' + cntr.Id + '&id=' + cntr.Id + '&noopptt=' + cntr.Company + '-' + cntr.Name);
         return redirecturl;


I do I get test coverage for this page so that we can deploy it production from our sandbox?

Ankit AroraAnkit Arora

Writing a test class for standard controller which is your case is not covered in the link provided by Shashikant. Here are some good links :




Covering all cases in test class :




Another very good link : 





Ankit Arora


Shashikant SharmaShashikant Sharma


Thanks for reading my blog but my friend you missed that i also provided standard controoler case in example



private class testApexClass{

    private static TestMethod void testClassMethod(){
        //Step 1 : Data Insertion
        //Insert all the data required for your trigger according to your logic written in the trigger
        //Try to give unique values in fields while creating test data, like Name = 'TestAccountName' etc
        //If any configuration setting is also needed in your trigger insert that as well
        //If you create any configuration setting then you will need to create a user also so that mixed dml exception do not occur
        //If class has a constructor with parameter Standard Controller, that means VFP is using this class as extention and has a standard controller then please create a standard controller prior to instance of class

        //Create instance of Class 
        MyClass cls = new MyClass();

        //call the method that you want to test using instance of class
        //assert your results using system.assert and system.asserEquals 
        // IF you have used any static variables



I hope you can see it now.


Ankit AroraAnkit Arora

To be more specific if newbie's are asking for test classes then just a simple text won't help them much I guess.


If you are writing a blog over test classes then it would be helpful for all if you provide some test samples and code to get broad view.


Hope you got my point this time.



Ankit Arora


Shashikant SharmaShashikant Sharma

First of all newbie's is only status for community not for his understanding level . I think we all are newbie and learning thing here. Yes it might be not be possible that it is not helpful for him , it might be possible links that you provided are also not helpful, but I think whether they are or not can only be decided by them only not by us. And you cahnged your stance first you said I did not provide standard controlle in example , now when I showed you lines those give instructions for them you are saying not much help , whats your intension Mate :)