Creating two column layout in Flow

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags with 17 Comments on Creating two column layout in Flow

Simple utility to convert One column to Two column layout in Salesforce Flow

Salesforce Two column layout in Flow
Salesforce Two column layout in Flow

Salesforce flow does not support two column page layout in flow, please vote this idea if you want it as out of box functionality.

However, using below solution we can convert single column page layout to double column layout in flow.

We need to embed flow in below Visualforce. Not necessarily you need to have a knowledge of Visualforce code, simply copy paste in your Salesforce organization and replace flow name with your flow name in your organization. This Visualforce page uses JQuery library to manipulate DOM element. Please download latest version of JQuery and save it as static resource with name “JQuery2_1_4” or you can also update static resource name in below code.

You can use variable “ignoreTableRows” to add row numbers or field sequence which you don’t want to covert as two column. I have added as much as comment to make code self explanatory.

Visualforce page:

 
<!-- Author : Jitendra Zaa Description : Below Visualforce page converts single column flow to double column layout -->
<apex:page >
    <!-- Enter your flow name below -->
    <flow:interview name="Two_column_flow" finishLocation="/{!$CurrentPage.parameters.id}">
        <apex:param name="varFlowVar" value="{!$CurrentPage.parameters.id}"/>
    </flow:interview> 
    
    <apex:includeScript value="{!$Resource.JQuery2_1_4}"/>
    
    <script>
        //row number of fields which should be rendered as single column, index starts with 0.
    	var ignoreTableRows = [0,1,6];
    	
    function isValidRow(rowIndex){
      for(var j = 0; j< ignoreTableRows.length; j++)
          {
          	 if(rowIndex == ignoreTableRows[j])
                 return false;
          }
        return true;
      }
        
    $(function() {
        var tableRowCounter = 0;
        var tbl = $('table .detailList');
        var rows = $('tr', tbl);        
       var i = 0;
        for(i = 0; i<rows.length;i++){ 
          if(isValidRow(i)) { 
           var currentRow = $('tr:eq('+i+')', tbl); 
           var nextRowIndex = i+1; //check if next row is valid             if(!isValidRow(nextRowIndex)) { 
   while(!isValidRow(nextRowIndex)) { 
           nextRowIndex = nextRowIndex +1; 
                if(nextRowIndex >= rows.length)
                        break;
                    }
                }
                var nextRow = $('tr:eq('+nextRowIndex+')', tbl);                
                if(nextRow) {
                    var currentColumns = $('td', currentRow);
                    var nextRowColumns = $('td', nextRow);
                    
                    if(currentColumns[2] && currentColumns[3]) {
                        //remove 3rd and 4th column
                        $(currentColumns[2]).remove();
                        $(currentColumns[3]).remove();                        
                        $(nextRowColumns[0]).detach().appendTo(currentRow);
                        $(nextRowColumns[1]).detach().appendTo(currentRow);  
                        $(nextRow).remove(); 	
                      } 
                 } 
            } 
        }         
    }); 
    </script>


<style type="text/css">
        .dataCol, .labelCol{
            padding-top: 5px !important;
            padding-bottom: 5px !important;
        }
    </style>


</apex:page>

Demo output :

Preview Column 1 to Column 2 in Salesforce flow
Preview Column 1 to Column 2 in Salesforce flow

Related posts

  • Radnip

    It’s a shame Salesforce pulled out Javascript from the actual flows. I can understand why they did it, but did make doing this kinda of thing a hell of a lot easier!

    • Ohh.. I actually didn’t knew that we had capability for Javascript, I started using flow recently only.

  • Patricia Sterling – OIT

    Error: No variable named “varFlowVar” in flow. how to use this statement to get the 2 column layout a flow

    • Raghu

      did you figured out that “VarFlowVar” ??

      • You would need to define this variable in your flow or ignore line number 5 in above code.

        • Raghu

          Hi Ji,

          Thanks for the reply ..
          I deleted the line 5, but still no luck .. ?

          Not Sure If I am doing this part correctly ” Please download latest version of JQuery and save it as static resource with name “JQuery2_1_4” ”

          Please guide me.

          Thanks,
          Raghu

          • Ram

            Hi Raghu ,

            Any luck ? I was stuck at the same point . Even after having the proper static resource for me it is still the same single column with 10 fields . Any help here is appreciated . Thanks .

          • You would need to download JQuery from below link and upload as static resource https://jquery.com/download/

          • Ram

            Hi Jitendra,

            I downloaded the jquery tried both (Download the compressed, production jQuery 3.0.0

            Download the uncompressed, development jQuery 3.0.0) and uploaded as static resource but it still shows as same one column layout . I am attaching the screenshots . Please help on this.

            My Code :

            //row number of fields which should be rendered as single column, index starts with 0.

            var ignoreTableRows = [0,1,6];

            function isValidRow(rowIndex){

            for(var j = 0; j< ignoreTableRows.length; j++)

            {

            if(rowIndex == ignoreTableRows[j])

            return false;

            }

            return true;

            }

            $(function() {

            var tableRowCounter = 0;

            var tbl = $('table .detailList');

            var rows = $('tr', tbl);

            var i = 0;

            for(i = 0; i= rows.length)

            break;

            }

            }

            var nextRow = $(‘tr:eq(‘+nextRowIndex+’)’, tbl);

            if(nextRow) {

            var currentColumns = $(‘td’, currentRow);

            var nextRowColumns = $(‘td’, nextRow);

            if(currentColumns[2] && currentColumns[3]) {

            //remove 3rd and 4th column

            $(currentColumns[2]).remove();

            $(currentColumns[3]).remove();

            $(nextRowColumns[0]).detach().appendTo(currentRow);

            $(nextRowColumns[1]).detach().appendTo(currentRow);

            $(nextRow).remove();

            }

            }

            }

            }

            });

            .dataCol, .labelCol{

            padding-top: 5px !important;

            padding-bottom: 5px !important;

            }

          • Raghu

            Hi Ji,

            I am getting this error ?

            Thanks,
            Raghu

          • Raghu

            Sorry forgot the attachment..

          • Ram

            Hi ,

            Can someone please help with my query.

            Thanks,
            Ram

          • Hi Ram,
            Can you check if you are getting any error in javascript console ? If you are on chrome click “Ctrl+Shift+J” or in IE press F12

          • Ram

            Hi Jitendra,

            I am seeing two errors . One error which is related to “failed to load resource” i was not sure what it is at all . I am not using that resource anywhere in my code and the code i am using is exact replica of yours . Please take a look in to the screenshot .Thanks.

          • Ram

            Hi Jitendra,

            Its working for me thanks for all your help.

          • Raghu

            Hi Ram,

            Does it works ??

            Please share how ?

            Thanks,
            Raghu

          • Ram

            Copy the above code mentioned and remove the flow variable . It worked for me .