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
Michaela ChrysostomouMichaela Chrysostomou 

I have the following apex class which is redirect my flow to the record that just created

Controller
public class FlowController {
 public Flow.Interview.Computer_Forms theFlow {get; set;}
 public PageReference getNewDispatchRecord(){
 if(theFlow == null)
return null;
else if(theflow.neorecord!=null)
return new PageReference('/' + theFlow.neorecord);
else
return new PageReference('/a28');
}
}

Test Class


@isTest 
private class FlowControllerTest {
   public static testMethod void myTestMethodForFlow() {
                  FlowController aFlowController = new FlowController();       
        aFlowController.theFlow= new Flow.Interview.Computer_Forms (new Map<String, Object>());
               PageReference pageRef = Page.VF_for_flow_in_CF;
                  Test.setCurrentPage(pageRef);
       string neorecord='a28550000001jch';
       string OwnerId='00516000006jIub';
       string Type='Desktop';
       string workload='Normal';
       string Reason='New';
       string OS_choice='Aple';
       
        }
        }


I get code covarage 14%. Any help?
RaidanRaidan
You have to call the aFlowController method. Probably twice: once before you set the neorecord and another after you set the value. If necessary, also call the method before you set theFlow variable so it will hit the theFlow == null branch. See example below.
FlowController aFlowController = new FlowController();
aFlowController.getNewDispatchRecord();

aFlowController.theFlow= new Flow.Interview.Computer_Forms (new Map<String, Object>());
aFlowController.getNewDispatchRecord();

string neorecord='a28550000001jch';
aFlowController.getNewDispatchRecord();
Michaela ChrysostomouMichaela Chrysostomou
I try the above but my class is failed to pass and the error is: System.FlowException:Interview not started.
But after that I run the flow through a button that is called a Visual force page  VF_for_flow_in_CF which is called the flow. Then the code covarage is increased in 71%.