+ Start a Discussion
Vipin K 10Vipin K 10 

Order Creation from Flows

Hi All,

I have created visual flow to create order from Quote with line items assignment. Have a generate button on quote which would tigger the flow and order gets created. 
Issue is the order gets created and but it stays on the quote page itself. My requirement is once the order is created it should navigate to Order screen with created order.

Can someone help!
Best Answer chosen by Vipin K 10
Rakesh51Rakesh51
Hi Vipin,

After creation of new record, if you wnat to redirect your to it then you have to use visualforce page with Apex.

Steps
1) In your Flow Craete a new variable lets say NewOrderID
2) Craete a Visualforce page and then embed your Flow into it
3) Now use Apex class to get the newly created Order ID from Flow and pass it to your Visualforce page.
<apex:page standardController="Order" extensions="RenewPolicyFlow">
    <flow:interview name="Renew_Policy_Flow" interview="{!myFlow}" finishLocation="{!Redirect}"/>
</apex:page>
---------------------------------------------------------------------------------------------
public class RenewPolicyFlow{
    public RenewPolicyFlow() {
    }
    public RenewPolicyFlow(ApexPages.StandardController controller) {
    }
    public Flow.Interview.Renew_Policy_Flow myFlow{get; set;}
    Public PageReference getRedirect(){
        String finishLocation;
        if(myFlow!= null) {
            finishLocation = (string) myFlow.getVariableValue('NewOrderID');
        }
        PageReference send = new PageReference('/' + finishLocation);
        send.setRedirect(true);
        return send;
    }
}


 

All Answers

Rakesh51Rakesh51
Hi Vipin,

After creation of new record, if you wnat to redirect your to it then you have to use visualforce page with Apex.

Steps
1) In your Flow Craete a new variable lets say NewOrderID
2) Craete a Visualforce page and then embed your Flow into it
3) Now use Apex class to get the newly created Order ID from Flow and pass it to your Visualforce page.
<apex:page standardController="Order" extensions="RenewPolicyFlow">
    <flow:interview name="Renew_Policy_Flow" interview="{!myFlow}" finishLocation="{!Redirect}"/>
</apex:page>
---------------------------------------------------------------------------------------------
public class RenewPolicyFlow{
    public RenewPolicyFlow() {
    }
    public RenewPolicyFlow(ApexPages.StandardController controller) {
    }
    public Flow.Interview.Renew_Policy_Flow myFlow{get; set;}
    Public PageReference getRedirect(){
        String finishLocation;
        if(myFlow!= null) {
            finishLocation = (string) myFlow.getVariableValue('NewOrderID');
        }
        PageReference send = new PageReference('/' + finishLocation);
        send.setRedirect(true);
        return send;
    }
}


 
This was selected as the best answer
Vipin K 10Vipin K 10
Hi Rakesh,

Thanks for the reply.  I tried this but it did not work. I have some questions.

1. I am using an button with following url : /flow/Quote_to_Order?QuoteID={!Quote.Id}&retURL=/{!Order.Id} - But it lands me on home page.
    Button is on Quote Page.
2. Where should i place the VF page if i create? on the button?

 
Rakesh51Rakesh51
1. in the button you have to use Visualforce page not any URL like this /flow/Quote_to_Order?QuoteID={!Quote.Id}&retURL=/{!Order.Id}
2. You have to manage redirect logic in Visualforce page as mentioned in the above code
Vipin K 10Vipin K 10
I have created a button on Quote. But this VF page Standard Controller is on Order. I will not be able to select this VF page on Quote button.
Rakesh51Rakesh51
Use Quote as Standrad controller standardController="Quote"
Ronaldo Costa 8Ronaldo Costa 8
Hi, do you have a test class for the code you provided above? thanks!