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
jpb@uhcjpb@uhc 

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:"
                      subtitle="{!lead.name}"/>
  <apex:form >
    <apex:pageBlock title="Create TeamTrack Flag" id="thePageBlock"
                    mode="edit">
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
      <FONT COLOR="RED"><b>IMPORTANT: </b> Should a TeamTrack be created for this Opportunity?</FONT>
              <br /><br />
        <table>
        <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>
        </table>
        <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" />
    </apex:pageBlock>
  </apex:form> 
</apex:page>

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);
         redirecturl.setRedirect(true);
         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 :

 

http://salesforcesource.blogspot.com/2008/09/testing-your-controller-extentions.html

 

Covering all cases in test class :

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm

 

Another very good link : 

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

 

Thanks
Ankit Arora

 

Shashikant SharmaShashikant Sharma

@ankit

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

 

 

@isTest
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();

        test.startTest();
        
        //call the method that you want to test using instance of class
        cls.MethodToTest()
        
        //assert your results using system.assert and system.asserEquals 
        
        test.stopTest();
        // 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.

 

 

Thanks
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 :)