Activity Forums Salesforce® Discussions Adding Flows to Visualforce Pages

  • shariq

    Member
    September 21, 2018 at 7:25 am

    Hi,

    To customize a flow’s look and feel or enhance its functionality, embed it in a Visualforce page. If your org has flows enabled for sites and portals, use the Visualforce page to deliver the flow to your Salesforce site, portal, or community.
    Users can run only flows that have an active version. If the flow you embed doesn't have an active version, users see an error message. If the flow you embed includes a subflow element, the flow that is referenced and called by the subflow element must have an active version.
    To add a flow to a Visualforce page, embed it using the <flow:interview> component:Find the flow's unique name:From Setup, enter Flows in the Quick Find box, then select Flows.
    Click the name of the flow that you want to embed.
    Define a new Visualforce page or open one that you want to edit.
    Add the <flow:interview> component, somewhere between the <apex:page> tags.
    Set the name attribute to the unique name of the flow. For example:

    <apex:page>
    <flow:interview name="MyUniqueFlowName"/>
    </apex:page>

    Hope this helps.

    • This reply was modified 6 years, 2 months ago by  shariq.
  • shariq

    Member
    September 21, 2018 at 7:25 am

    Hi,

    To add a flow to a Visualforce page, embed it using the <flow:interview> component:Find the flow's unique name:From Setup, enter Flows in the Quick Find box, then select Flows.
    Click the name of the flow that you want to embed.
    Define a new Visualforce page or open one that you want to edit.
    Add the <flow:interview> component, somewhere between the <apex:page> tags.
    Set the name attribute to the unique name of the flow. For example:

    <apex:page>
    <flow:interview name="MyUniqueFlowName"/>
    </apex:page>

    If the flow is from a managed package, the name attribute must be in this format: namespace.flowuniquename.

    Restrict which users can run the flow by setting the page security for the Visualforce page that contains it.To run the flow, external users (such as on a community) need access to the Visualforce page. To run the flow, internal users need access to the Visualforce page and either:The "Run Flows" permission
    The Flow User field enabled on their user detail page

    Thanks

    • This reply was modified 6 years, 2 months ago by  shariq.
  • Parul

    Member
    September 21, 2018 at 7:28 am

    Execute the following code.
    Id <variable name>= Database.executeBatch(new <Class name>(), batch size);

     

    Thanks

  • Parul

    Member
    September 21, 2018 at 7:34 am

    Adding some points:

    It is not possible to add a Visualforce page within a flow, e.g. there is no way to see it as an option in the Flow Builder. The only method to switch to visualforce is using a page as a wrapper for the flow and passing control to it by setting a variable value within the flow, which there is an example of

    Add the following to the controller

    public Attachment attachment {
    get {
    if (attachment == null)
    attachment = new Attachment();
    return attachment;
    }
    set;
    }

    // Specific flow name for flow type
    public Flow.Interview.my_flow myflow { get; set; }

    public String varCaseId;
    public String varUpload;
    public Boolean upload;
    public Boolean uploaded = false;
    public String fName{ get; set;}
    public String displayName{get; set;}

    // The Case Id value from the flow
    public String getvarCaseId()
    {
    If(myFlow == null)
    Return null;
    Else
    return myflow.varCaseId;
    }

    // The varUpload variable value from the flow
    public String getvarUpload()
    {
    If(myFlow == null)
    Return String.valueOf('0');
    Else
    Return myflow.varUpload;
    }

    Public Boolean getupload()
    {
    If(myFlow != null && myflow.varUpload != null && myflow.varUpload == '1' && uploaded!= null && uploaded == false)
    Return true;
    else
    Return false;
    }

    // Save method, leading to next step in flow
    public PageReference Save()
    {
    return upload(System.Boolean.valueOf(true));
    }

    // Save More method, leading to the attachment upload functionality again
    public PageReference SaveMore()
    {
    return upload(System.Boolean.valueOf(false));
    }

    // Cancel method, leading to next step in flow
    public PageReference Cancel()
    {
    This.uploaded = true;
    attachment = null;
    return null;
    }

    // Upload method for actual attachment upload, setting the upload variable appropriately to allow/ not allow another attachment upload
    public PageReference upload(Boolean varUploaded)
    {
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = getvarCaseId(); // the record the file is attached to
    attachment.IsPrivate = false;

    if( (!(attachment.name != null && attachment.name != '')) && (fName != null && fName != ''))
    {
    String afterExt = fName.substringAfter('.');
    System.debug('afterExt :: ' + afterExt );
    if(displayName != null && displayName != '')
    {
    attachment.name = displayName + '.' + afterExt;
    }
    else
    attachment.name = fName;
    }
    try
    {
    if(!(attachment.body != null))
    {
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please specify a file to be uploaded'));
    }
    else if (!(attachment.name != null && attachment.name != ''))
    {
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Please specify a file name'));
    }

    insert attachment;
    displayName = '';
    fName = '';

    }
    catch (DMLException e)
    {
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
    return null;
    }
    finally
    {
    attachment = new Attachment();
    }

    This.uploaded = varUploaded;
    // true for save and false for Save more
    return null;

    // End of upload
    }
    Visualforce page

    <apex:outputPanel id="theAttachmentPanel" rendered="{!upload}">
    <apex:sectionHeader title="Attachment Upload (Upto 10 MB)"/>

    <apex:pageMessages />
    <apex:pageBlock title="Upload an Attachment">

    <apex:pageBlockButtons >
    <apex:commandButton action="{!SaveMore}" value="Upload More"/>
    <apex:commandButton action="{!Save}" value="Finish Uploading"/>
    <apex:commandButton action="{!Cancel}" value="Submit with no Attachment"/>
    </apex:pageBlockButtons>

    <apex:pageBlockSection showHeader="false" columns="2" id="block1">

    <apex:pageBlockSectionItem >
    <apex:outputLabel value="File Name" for=" filesName "/>
    <apex:inputText value="{!displayName}" id="filesName"/>
    </apex:pageBlockSectionItem>

    <apex:pageBlockSectionItem >
    <apex:outputLabel value="File" for="file"/>
    <apex:inputFile value="{!attachment.body}" filename="{!fName}" id="file"/>
    </apex:pageBlockSectionItem>

    <apex:pageBlockSectionItem >
    <apex:outputLabel value="Description" for="description"/>
    <apex:inputTextarea value="{!attachment.description}" id="description"/>
    </apex:pageBlockSectionItem>

    </apex:pageBlockSection>
    </apex:pageBlock>

     

    Hope this will help you.

     

    Thanks

    • This reply was modified 6 years, 2 months ago by  Parul.

Log In to reply.

Popular Salesforce Blogs