4

I am trying to override a Salesforce standard button on the case page layout (Clone As Child Button) - which will create a related child case with some of the fields from the parent copied over. Because of my implementation the fields have to be copied explicitly (rather than the out of the box salesforce functionality).

So I've created a Flow - which when fired takes the parent Case ID - copies some of it's fields over to the new related child case, then copies the ID of the new child case in a Flow output variable.

The Flow itself works fine (tested) - what I want to do now is when that button is clicked that the Flow be fired - then the page redirected to the Child Case edit page.

For that I have a VF page and a controller. The VF page simply fires the Flow:

<apex:page standardController="Case" extensions="CreateChildFlowController">
    <br/>
        <flow:interview name="CreateChildFlow" interview="{!childCaseFlow}" finishLocation="{!ForwardURL}"/>
</apex:page>

And for the Apex controller I have had to create an extension controller (because apparantly you cannot override a standard Salesforce button to call a custom controller - it has to have a standard controller):

public class wtrCreateChildFlowController 
{

    public Flow.Interview.wtr_CreateChildFlow childCaseFlow { get; set; }

    private ApexPages.StandardController standardController = null;


    public wtrCreateChildFlowController(ApexPages.StandardController stdController)
    {
        standardController = stdController;
    }

    public String getNewCaseID() {
        if (childCaseFlow==null) return '';
        else return childCaseFlow.newCase;
    }

    public PageReference getForwardURL(){
        PageReference p = new PageReference('/' + getNewCaseID() + '/e?retURL=/' +getNewCaseID());
        System.debug('PageReference.Url = ' + p.getUrl());
        p.setRedirect(true);
        return p;
    }
}

So when the Clone As Child is clicked (that's the New Case -> Related Case: Copy from PArent button) the following happens:

  1. The button reaches the VF page properly
  2. The Flow is triggered properly
  3. The Child Case gets created and the proper fields get copied
  4. The page then gives an "Invalid URL" error

Nothing in the logs shows this error - and when I have debugged to the log (as you can see above) - it turns out that the new case ID always returns blank (clearly because it is null).

My dilemma is if the new child case gets created - why when I reference the flow to get the ID back does it always come back as blank? (Is this a scope issue?)

Also I believe this works if it's a custom controller rather than an extension controller (don't know why). Help!!

  • I have seen stuff like this work, also as an extension. I don't see anything wrong with the Apex code, looks to me the issue is: why doesn't the flow return anything in newCase? – Sander de Jong Jul 29 '15 at 9:37

Your Answer

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

Browse other questions tagged or ask your own question.