[SalesForce] Populate Flow variable with Parent Id – from VisualForce page – launched by related list Custom Button

I have created a Flow which allows my users to insert multiple Currency_Detail__c records from one page.

The Currency Detail records have a Master-Detail relationship with Opportunities. I have created a variable in the Flow OppId which, as the name suggests, will store the Id of the Opportunity which each Currency Detail record needs to be related to.

I now need to add a custom button to the Currency Detail related records list, to launch the Flow and to populate the OppId variable, with the Id of the Opportunity which the user is viewing.

I've created this VisualForce page

<apex:page standardController="Currency_Detail__c" recordSetVar="Currency_Details">
   <flow:interview name="Create_Currency_Detail_Records" finishLocation="/{!Id}"/>
   <apex:param name="OppId" value="{!Id}"/>
</apex:page>

But when I use this, it causes an error

(REQUIRED_FIELD_MISSING) Required fields are missing: [Opportunity__c] — for SFDC record with ID : null

so it looks like the variable's not being populated.

This is probably completely off the mark but I can't save the page if I change value="{!Id}" to value="{!Opportunity.Id}"

Unknown property 'Currency_Detail__cStandardController.Opportunity'

How can I populate the Flow's OppId variable from the VisualForce page?

UPDATE

Just to make sure that the setup of my Flow's not the cause of the issue, this is how the Record Create elements are configured

Record Create Screen

The other two fields are taking their values from screen input fields on a screen element earlier in the Flow.

The OppId variable is set to Input & Output.

Best Answer

You have to make the Custom Button as an onclick javascript button and then open the VF Page by passing the opportunity id as a parameter to the page (say call id oppId) and then pass that parameter to the flow..

so your Custom Button properties will be

  • Display Type - List Button
  • Behaviour - Execute Javascript
  • Content Source - Onclick Javascript

and then in the script section point it to your VF page with the param

window.location = '/apex/YourVFPage?oppId={!Opportunity.Id}'

then in your VF page you can do

UPDATE :

the param tag was outside the flow tag which is why the value was not getting passed into the flow.. please use the correct syntax as below

<apex:page standardController="Currency_Detail__c" recordSetVar="Currency_Details">
   <flow:interview name="Create_Currency_Detail_Records" finishLocation="/{!Id}">
       <apex:param name="OppId" value="{!$CurrentPage.parameters.oppId}"/>
   </flow:interview>
</apex:page>
Related Topic