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
Tasia Demuth 4Tasia Demuth 4 

MultiAdd Action in VF page

I have a visualforce page that calls a flow that creates an opportunity. I would like the finish location to be the multiadd action, so the user can add products to the newly created opportunity. 

Here is my code so far. Any suggestions?

<apex:page standardController="Opportunity" recordSetVar="opportunities">
    <flow:interview name="CreateOpportunityFlow" finishLocation="<apex:outputLink>{!URLFOR($Action.OpportunityLineItem.MultiAdd)}</apex:outputLink>">
        <apex:param name="AccountId" value="{!$CurrentPage.parameters.Id}"/>
    </flow:interview>
</apex:page>
Best Answer chosen by Tasia Demuth 4
Alain CabonAlain Cabon
Hi,

Get Flow Variable Values to a Visualforce Page: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_getting_values.htm

Configure the finishLocation Attribute in a Flow:   https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_finishlocation.htm

The actions are a restrictted list:   https://help.salesforce.com/articleView?id=dev_action_values.htm&language=en&type=0

User-added image

I didn't find "MultiAdd" but the compilation is OK with this action so that must work and the list is out-of-date.

Anyway, the following POC needs a controller (without using "MultiAdd").

User-added image

The record ID of the created opportunity is assigned to {!flow_oppid} 

User-added image

But we need an output variable : oppId

User-added image

 
public with sharing class OppCreateController {
    
    public Flow.Interview.testflow3 OppCreate{get;set;}    
    
    public String getOppId(){
        String oppId = null;
        if(OppCreate!= null) oppId = OppCreate.oppId;
        return oppId;       
    }
    public PageReference getBackToOpp() {
        String returnId = null;
        if(OppCreate!= null) returnId = OppCreate.oppId;    
        PageReference send = new PageReference('/p/opp/SelectSearch?addTo=' + returnId + '&retURL=%2F' + returnId);
        send.setRedirect(true);
        return send;        
    }
}
 
<apex:page controller="OppCreateController">
    <!-- >> KO << flow:interview name="Testflow3" interview="{!OppCreate}" finishLocation="{!URLFOR($Action.OpportunityLineItem.AddProduct,OppId)}" / -->  

    <flow:interview name="Testflow3" interview="{!OppCreate}" finishLocation="{!BackToOpp}" />

</apex:page>

That works.

Regards
Alain

All Answers

Alain CabonAlain Cabon
Hi,

Get Flow Variable Values to a Visualforce Page: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_getting_values.htm

Configure the finishLocation Attribute in a Flow:   https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_finishlocation.htm

The actions are a restrictted list:   https://help.salesforce.com/articleView?id=dev_action_values.htm&language=en&type=0

User-added image

I didn't find "MultiAdd" but the compilation is OK with this action so that must work and the list is out-of-date.

Anyway, the following POC needs a controller (without using "MultiAdd").

User-added image

The record ID of the created opportunity is assigned to {!flow_oppid} 

User-added image

But we need an output variable : oppId

User-added image

 
public with sharing class OppCreateController {
    
    public Flow.Interview.testflow3 OppCreate{get;set;}    
    
    public String getOppId(){
        String oppId = null;
        if(OppCreate!= null) oppId = OppCreate.oppId;
        return oppId;       
    }
    public PageReference getBackToOpp() {
        String returnId = null;
        if(OppCreate!= null) returnId = OppCreate.oppId;    
        PageReference send = new PageReference('/p/opp/SelectSearch?addTo=' + returnId + '&retURL=%2F' + returnId);
        send.setRedirect(true);
        return send;        
    }
}
 
<apex:page controller="OppCreateController">
    <!-- >> KO << flow:interview name="Testflow3" interview="{!OppCreate}" finishLocation="{!URLFOR($Action.OpportunityLineItem.AddProduct,OppId)}" / -->  

    <flow:interview name="Testflow3" interview="{!OppCreate}" finishLocation="{!BackToOpp}" />

</apex:page>

That works.

Regards
Alain
This was selected as the best answer
Tasia Demuth 4Tasia Demuth 4
Hi Alain, 

This is awesome! I do run into one issue. My URL keeps routing to this: https://cs50.salesforce.com/p/opp/SelectSearch?addTo=null&retURL=%2Fnull

Null is populating instead of the id. When I replace null with the id manually it works really well! Do you know why I might not be automatically getting the ID set into that url? 

Thanks for your help!!
Tasia
Alain CabonAlain Cabon
Hi Tasia,

The workflow can be simplified using OppId directly as shown below ( you have probably changed that yet ).

If you run the workflow directly (button "run") that doesn't work when you click "finish".
You always need to launch the workflow from the VFP as you have done ( /apex/myVFPname )

Could you show me your controller?

You could need something more suitable for your need.

<apex:page standardController="Opportunity" recordSetVar="opportunities">

The sample is very simple and my custom controller is sufficient for the basic test but you have used a standard controller for a list (more complex).

User-added image

Best regards

Alain
Tasia Demuth 4Tasia Demuth 4
Alain, you are great! 

You were right. I had not set the variable oppId in the flow correctly. I got it running smoothly.

I really appreciate your help!
Tasia
Tasia Demuth 4Tasia Demuth 4
Hi Alain, 

I am wondering if you can help me with one more thing related to this question. 

We are moving over to lightning and I would like to redirect to the Lightning version of MultiAdd instead of the classic. Is there a way to do this? 

I think the code I need to change is below: 

PageReference send = new PageReference('/p/opp/SelectSearch?addTo=' + returnId + '&retURL=%2F' + returnId);

Let me know. 

Thanks!
Tasia