I have a controller that initiates a flow when a button is clicked on a lead. I understand that unit test classes cannot make web callouts, so I have created a class that implements the HttpCalloutMock interface as specified in this documentation. The definition of my controller is as follows:

public class ISI_Controller 
    private final Lead lead;
    public Flow.Interview.SI myFlow {get; set; }
    public String leadID;

    public ISI_Controller(ApexPages.StandardController stdController)
    this.lead= (Lead) stdController.getRecord();

    public Lead getLead()
        return lead;

So far, I have the following code that creates a lead and sets the mock http response. How do I test my controller?

public class ISI_Controller_Test 
    static testMethod void basicTest()
        Lead testLead = new Lead(LastName = 'Test',
                                 Phone = '7045555555',
                                 Company = 'Test',
                                 LeadSource = 'Telemarketing',
                                 Sales_Type__c = 'New',
                                 Customer_Type__c = 'Residential',
                                 Product_Interest__c = 'Security');
        insert testLead;

        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());

VisualForce Page Code:

<apex:page standardController="Lead" extensions="ISI_Controller" tabStyle="Lead">
<flow:interview name="ISI" interview="{!myFlow}" finishLocation="/{!Lead.Id}">
    <apex:param name="LeadID" value="{!Lead.Id}"/>  
    <apex:param name="CurrentUserID" value="{!$User.Id}"/> 
    <apex:param name="LeadOwnerID" value="{!Lead.OwnerId}"/>

  • 2
    Is your flow making a web services call? If not, why do you feel you need the mock callout? What portions of your controller aren't being covered by your test class? Where are stuck? What does your flow do as in what's the outcome of the flow? You'll want to assert the results at the end of the test class. You use an Apex Page with standard controller in your class, where that's addressed in your test class?
    – crmprogdev
    May 1 '15 at 15:29
  • My flow is updating records - I was confused because I didn't think I was making any kind of web services call. I attempted to run the test and received an error message that SF does not support unit tests for web callouts. I can provide the code for my VF page if that would be helpful. May 1 '15 at 19:15
  • Your VF page code would probably be more helpful along with any controllers that are used in it as well. Clearly you don't need the mock callout, but you do need to initialize your page.
    – crmprogdev
    May 1 '15 at 19:44

I'm assuming your flow is an interactive flow? If so, you can't test it.

If it is a trigger-ready flow, then you need to use the start() method to trigger the flow.

Inside_Sales_Information_Controller isiController = new Inside_Sales_Information_Controller();
isiController.myflow = new Flow.Interview.SalesInformation(new Map<String, Object>());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.