+ Start a Discussion
Derek Davis 7Derek Davis 7 

New to APEX.... Class Working but Example/Explaination of Test Class Needed

Hi All - I am very familiar with Salesforce but newer to APEX. I recently created an APEX Class to change the behavior of a Flow Finish Button. When the finish button is clicked this class sets the URL and sets the referenced variables within the URL.

The class is working, but I'm not sure about how to go about creating the test coverage for the Class shown below. Any assistance would be appreciated!!

VF Page -
<apex:page Controller="OpptyFlowController" TabStyle="Opportunity">
    <br/>
    <flow:interview name="CreateOppty" interview="{!myflow}" finishlocation="{!OID}" />
</apex:page>

Here is the Class -
public class OpptyFlowController {

public Flow.Interview.CreateOppty myFlow { get; set; }

public String getmyID() {
if (myFlow==null) return '';
else return myFlow.OpptyID;
}

public PageReference getOID(){
PageReference p = new PageReference('/apex/opportunityProductEntry?id=' + getmyID() + '&addTo=' + getmyID() + '&retURL=%2F006%2Fe&sfdc.override=1');
p.setRedirect(true);
return p;
}

}
Best Answer chosen by Derek Davis 7
William TranWilliam Tran
Do you need a test class to get test coverage?  If so, just create a test class and call the methods such as getOID and getmyID.
If you don't get 100%, you will need to tweak it to get more coverage.

Thx
@isTest
private class myflowTest 
{
    private static testMethod void Testflow() 
    { 
        test.startTest();
         try
         {
            OpptyFlowController sc = new OpptyFlowController();
            sc.getmyID();
            sc.getOID();
        }
        catch(Exception ee){    }   

        test.stopTest();
    }
}
As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

Thanks