Find The Window URL In A Visualforce Sidebar Component

So the question “Know previous page in Winter ’18” answers my question as to why my packaged Visualforce sidebar component is now failing to find the window’s URL correctly to work out the context of what is being viewed.

Of course, now I need a genuine workaround as telling clients to disabled a security settings Salesforce themselves have added is by and large a non-starter. Would have been nice if there was an alternative level of protection that allowed Visualforce access, but that’s clearly not a thing.

So the question in short:

How do you get the window’s URL inside the controller for a Visualforce page hosted in the sidebar?


Not sure if I have undertood your question correctly, but only for this question “How do you get the window’s URL inside the controller for a Visualforce page hosted in the sidebar?” this is the approach to find out.

I had a requirement that during case creation the Parent object details must be shown as sidebar as follows.

To implement this functionality I have created a visualforce with controller and placed that visualforce as sidebar console component.


Here is the tricky part

We cannot get id the parent object in the controller. For this reason, in the visualforce page load I have called actionFunction to pass values to the controller.


<apex:page id="sidebarPage" Controller="SidebarComponentController" showHeader="false" sidebar="false">
    <apex:includeScript value="/support/console/28.0/integration.js" />
    <!-- On window load getEnclosingPrimaryTabId() is getting called to retrieve the tabLink which will be passed to actionFunction-->
    <!-- Function has been written as in controller, getParameters().get('Id') will not work in console -->
    <script type="text/javascript">
        var getEnclosingPrimaryTabId = function getEnclosingPrimaryTabId() {
        var getTabLink = function getTabLink(result) {
      , showTabLink);
        var showTabLink = function showTabLink(result) {
            var link = result.tabLink;
        window.onload = getEnclosingPrimaryTabId;               
    <apex:form id="form1">

        <apex:actionFunction name="passLinkFunc" action="{!init}" immediate="true" reRender="form1">
            <apex:param id="URLString" name="URLString" assignTo="{!URLString}" value="" />

            All necessary fields to display in the page



In the init method url will be captured like this:

From that url, we can get the id from Custom object through parsing logic.

public class SidebarComponentController 

    public String urlid{get;set;}
    public String URLString {get;set;}

    public SidebarComponentController() {
        System.debug('Inside Constructor=' + ApexPages.currentPage().getParameters());        

    public void init()
        System.debug('URLString=' + URLString);     
        String url = EncodingUtil.urlDecode(URLString, 'UTF-8');

        System.debug('init:url= ' + url);

        //retrieve CustomObject Id in New mode 
        //urlid= retriveQueryStringValue(url, 'CF00N0n000000gH4P_lkid');

        if(url.contains('CF00N0n000000gH4P_lkid'))  //put this in Custom label
            urlid= retriveQueryStringValue(url, 'CF00N0n000000gH4P_lkid');


    public String retriveQueryStringValue(String url, String input)
        String returnString = null;

        if(input != null)
            //this will return CustomObject Id
            Integer position = url.indexOf('?');
            if(position != -1)
                String queryString = url.substring(position + 1);
                List<String> parts = queryString.split('&');
                for(String str:parts)
                        returnString = str.substring(input.length()+1);
                        return returnString;

Let me know if it helps!

Source : Link , Question Author : Matt Lacey , Answer Author : Santanu Boral

Leave a Comment