You need to sign in to do that
Don't have an account?
Julianne Boley
Test Class for Controller Extension that sets the Finish Page for a Force.com Flow
I am not an advance developer by any definition, and I have been trying to figure this out pouring over other blogs and forums for days now. I finally give up and am hoping someone can help me.
I have a flow that I am calling and passing variables to via a custom button (Visualforce Page) on the Account detail page. The page setting the flow finish page and redirecting the user to the record created by the flow by using a controller extension.
Everything is working as it should, but I won't be able to move any of this to production until I can figure out a way to get test coverage of the controller extension.
This is the class:
public class takeMetoContractController {
public takeMetoContractController(ApexPages.StandardController controller) {
}
public Flow.Interview.Buan_Test rFlow {get; set;}
public String getcontractID() {
if (rFlow==null) return '';
else return rFlow.varMcContractID;
}
public PageReference getFinishPage(){
PageReference p = new PageReference('/' + getcontractID() );
p.setRedirect(true);
return p;
}
}
It is being used in this page:
<apex:page sidebar="false" standardController="Account" extensions="takeMetoContractController">
<flow:interview name="Buan_Test" interview="{!rFlow}" finishLocation="{!FinishPage}">
<apex:param name="Accountsfid" value="{!account.Id}"/>
<apex:param name="AccountSFName" value="{!account.Name}"/>
</flow:interview>
</apex:page>
I've got no idea how to get this test class to actually call the controller extension appropriately, but I have managed to get a test class to save. Here is what I have (no making fun, please):
@isTest
public class testtakeMetoContractController {
public static void testtakeMetoContractController() {
//Insert Account
Account acct = new Account(Name='TestClassAccount');
insert acct;
// Retrieve the new Account
acct = [SELECT Id,Name FROM Account WHERE Id =:acct.Id];
//Insert Contact
Contact c = new Contact (Account=acct, FirstName='Test', LastName='Contact');
insert c;
//Insert McContract
McContracts__c mc = new McContracts__c (Account_Name__c=acct.Id, Contact__c=c.Id);
insert mc;
//Retrieve the new Contract
mc = [Select Id, Name FROM McContracts__c WHERE Id =:mc.Id];
String mcID = mc.Id;
System.debug(mcID);
ApexPages.StandardController sc = new ApexPages.StandardController(acct);
takeMetoContractController ec = new takeMetoContractController(sc);
PageReference FlowContractPageRef = Page.FlowContract;
Test.setCurrentPage(FlowContractPageRef);
string vaMcContractId=mcId;
ec.getFinishPage();
ec.getContractId();
System.test.startTest();
System.debug('ContractId - Add ContractId');
System.debug('ContractId - Save');
System.test.stopTest();
}
}
It is clearly a mess, and I really have no idea what I am doing, so if anyone has a solution to this or feels like being a good samaritan and wants to help, it would be greatly appreciated.
I have a flow that I am calling and passing variables to via a custom button (Visualforce Page) on the Account detail page. The page setting the flow finish page and redirecting the user to the record created by the flow by using a controller extension.
Everything is working as it should, but I won't be able to move any of this to production until I can figure out a way to get test coverage of the controller extension.
This is the class:
public class takeMetoContractController {
public takeMetoContractController(ApexPages.StandardController controller) {
}
public Flow.Interview.Buan_Test rFlow {get; set;}
public String getcontractID() {
if (rFlow==null) return '';
else return rFlow.varMcContractID;
}
public PageReference getFinishPage(){
PageReference p = new PageReference('/' + getcontractID() );
p.setRedirect(true);
return p;
}
}
It is being used in this page:
<apex:page sidebar="false" standardController="Account" extensions="takeMetoContractController">
<flow:interview name="Buan_Test" interview="{!rFlow}" finishLocation="{!FinishPage}">
<apex:param name="Accountsfid" value="{!account.Id}"/>
<apex:param name="AccountSFName" value="{!account.Name}"/>
</flow:interview>
</apex:page>
I've got no idea how to get this test class to actually call the controller extension appropriately, but I have managed to get a test class to save. Here is what I have (no making fun, please):
@isTest
public class testtakeMetoContractController {
public static void testtakeMetoContractController() {
//Insert Account
Account acct = new Account(Name='TestClassAccount');
insert acct;
// Retrieve the new Account
acct = [SELECT Id,Name FROM Account WHERE Id =:acct.Id];
//Insert Contact
Contact c = new Contact (Account=acct, FirstName='Test', LastName='Contact');
insert c;
//Insert McContract
McContracts__c mc = new McContracts__c (Account_Name__c=acct.Id, Contact__c=c.Id);
insert mc;
//Retrieve the new Contract
mc = [Select Id, Name FROM McContracts__c WHERE Id =:mc.Id];
String mcID = mc.Id;
System.debug(mcID);
ApexPages.StandardController sc = new ApexPages.StandardController(acct);
takeMetoContractController ec = new takeMetoContractController(sc);
PageReference FlowContractPageRef = Page.FlowContract;
Test.setCurrentPage(FlowContractPageRef);
string vaMcContractId=mcId;
ec.getFinishPage();
ec.getContractId();
System.test.startTest();
System.debug('ContractId - Add ContractId');
System.debug('ContractId - Save');
System.test.stopTest();
}
}
It is clearly a mess, and I really have no idea what I am doing, so if anyone has a solution to this or feels like being a good samaritan and wants to help, it would be greatly appreciated.
You are doing good.
but forget some small things like
in TestClass TestMethod should have like this
you forget to wrtite testmethod keyword on it.
and no need to retrieve the new Account for id
like you do--- acct = [SELECT Id,Name FROM Account WHERE Id =:acct.Id];
just put acc.id in contact's account field.
like this
Contact c = new Contact (Account=acct.id, FirstName='Test', LastName='Contact');
And also in Contract query.
Let me knoe if ti helped .
Regards
Virendra
version7.7@hotmail.com (mailto:version7.7@hotmail.com)