1

We have a running functionality like there is a VF detail page and then there is an inline vf page which just contains couple of buttons. When we click on any button , new vf page opens in a new window.

Now what we want to achieve is that when we click a button on inline vf page , instead of opening a vf page in new window,we want to open that same window in place of the parent page.

Is this possible. Can some one guide me to a small demo if possible?

my inline vf page

<apex:page StandardController="gii__SalesOrder__c" extensions="giic_SalesOrderDetailButtonsCtrl">
        <apex:includeScript value="{!URLFOR($Resource.Datatable,'datatable/js/jquery-1.11.1.min.js')}"/>
        <apex:outputPanel id="scriptPanel">
            <script>
            <apex:repeat value="{!jsFunctionMap}" var="funcTemp">  
                {!jsFunctionMap[funcTemp]}
            </apex:repeat>
            $j = jQuery.noConflict();

            // Render table only when rest of document is loaded.
            $j(document).ready(function() { 
                tempFunction();
            });
            </script>
        </apex:outputPanel>
    <apex:form id="soBtnForm" styleClass="soBtnFormCls">
        <apex:actionFunction name="tempFunction" action="{!tempFunction}" rerender="scriptPanel"/>

        <apex:dynamicComponent componentValue="{!dynamicForm}"/>


        <apex:repeat value="{!jsFunctionMap}" var="funcTemp">  
           <apex:commandButton onclick="{!funcTemp}return false;" value="Say Hi"/>
        </apex:repeat>


    </apex:form>

</apex:page>

My controller

public class giic_SalesOrderDetailButtonsCtrl {

    public gii__SalesOrder__c salesOrder{get;set;}

    public Map<String, String> buttonsWithURLMap{get;set;}

    public Map<String, String> jsFunctionMap {get;set;}
    public String tempURL;

    //public List<Component.Apex.CommandButton> weblinks{get;set;}
    //public Component.Apex.CommandButton weblink{get;set;}

    public giic_SalesOrderDetailButtonsCtrl(ApexPages.StandardController controller) {
        salesOrder = (gii__SalesOrder__c) controller.getRecord();
        //weblinks = new List<Component.Apex.CommandButton>();
        buttonsWithURLMap = new Map<String, String>();
        jsFunctionMap  = new Map<String, String>();
        jsFunctionMap.put('tempFunc();','function tempFunc(){}');

        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        req.setHeader('Content-Type', 'application/json');
        req.setEndpoint('https://cs1.salesforce.com/services/data/v34.0/tooling/query/?q=SELECT+Id,+Description,+DisplayType,+LinkType,+FullName,+Metadata,+Name,+NamespacePrefix,+OpenType,+Position,ShowsLocation,+Url,+Width+FROM+WebLink+WHERE+EntityDefinition.QualifiedAPiName=\'gii__SalesOrder__c\'');
        req.setMethod('GET');

        Http http = new Http();
        Integer count = 1;
        String funcName = 'tempFunc';
        HttpResponse res = http.send(req);
        WebLinkList listButtons = (WebLinkList)JSON.deserialize(res.getBody(), WebLinkList.class); 
        for(WebLinkWrapper button: listButtons.records){
            if(button.LinkType == 'javascript'){
                jsFunctionMap.put(funcName+count+'();','function '+funcName+count+'(){'+button.Url+'}');
                count++;
            }
        }
    }

    public Component.Apex.PageBlock getDynamicForm() {
        Component.Apex.PageBlock dynPageBlock = new Component.Apex.PageBlock();

        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        req.setHeader('Content-Type', 'application/json');
        req.setEndpoint('https://cs1.salesforce.com/services/data/v34.0/tooling/query/?q=SELECT+Id,+Description,+DisplayType,+LinkType,+FullName,+Metadata,+Name,+NamespacePrefix,+OpenType,+Position,ShowsLocation,+Url,+Width+FROM+WebLink+WHERE+EntityDefinition.QualifiedAPiName=\'gii__SalesOrder__c\'');
        req.setMethod('GET');

        Http http = new Http();
        Integer count =1;
        String funcName = 'tempFunc';
        HttpResponse res = http.send(req);
        List<Component.Apex.CommandButton> weblinks = new List<Component.Apex.CommandButton>();
        WebLinkList listButtons = (WebLinkList)JSON.deserialize(res.getBody(), WebLinkList.class); 
        for(WebLinkWrapper button: listButtons.records){
            if(button.LinkType == 'url' || button.LinkType == 'page'){
                String url = button.Url;
                tempURL = url;
                buttonsWithURLMap.put(button.Metadata.masterLabel, url);
                Component.Apex.CommandButton weblink = new Component.Apex.CommandButton();
                weblink.value = button.Metadata.masterLabel;
                String Trul = '\''+'/servlet/servlet.Integration?scontrolCaching=1&lid='+button.id+'&eid='+salesOrder.id+'&ic=1'+'\'';
                weblink.onclick='openIntegration('+Trul+', "_self")';
                //weblink.onclick='navigateToUrl('+Trul+', \'DETAIL\');';
               // weblink.onclick='window.open('+Trul+',"_system")';

                weblinks.add(weblink);
            }
            if(button.LinkType == 'javascript'){
                Component.Apex.CommandButton weblink = new Component.Apex.CommandButton();
                weblink.value = button.Metadata.masterLabel;
                String tempId = String.valueOf(button.id).subString(0,15);
                weblink.onclick= funcName+count+'();return false';
                count++;
                weblinks.add(weblink);
            }
        }

        for(Component.Apex.CommandButton weblink: weblinks){
            dynPageBlock.childComponents.add(weblink);
        }
        return dynPageBlock;
    }

    public void tempFunction(){

    }

    public PageReference updateOrder(){
        PageReference pf = new PageReference('/apex/giic_checkValidationOrder?id='+salesOrder.gii__Account__c+'&button=order&soid='+salesOrder.id);
        return pf;
    }

    public class WebLinkList{
        public List<WebLinkWrapper> records{get;set;}
    }
    public class WebLinkWrapper{
        public String LinkType{get;set;}
        public String Name{get;set;}
        public String Id{get;set;}
        public String Url{get;set;}
        public WebLinkMetadata Metadata{get;set;}
    }

    public class WebLinkMetadata{
        public String masterLabel{get;set;}
    }
}

Thanks in Advance

2
  • what is the driving code behind the button in the inline VF page that you have clicked? JS or apex?
    – Prajith
    Jan 19, 2016 at 8:19
  • @stygon - does it matter in this case?
    – Samir
    Jan 19, 2016 at 8:32

1 Answer 1

1

you can use javascript for this try

window.opener.location.reload();

OR

window.opener.location.reload(false);

This will solve your problem.

5
  • can you suggest me where i need to make the change in my code.I have added the code
    – Samir
    Jan 19, 2016 at 8:54
  • <apex:commandButton value="{!btnName}" onclick="javascript:window.top.location={!URLENCODE(buttonsWithURLMap[btnName])}"/> change this into <apex:commandButton value="{!btnName}" onclick="window.top.location.reload(); return false;"/> Jan 19, 2016 at 8:58
  • But that line is commented.
    – Samir
    Jan 19, 2016 at 9:06
  • @Samir addthis onclick method on your button . I don't find it Jan 19, 2016 at 9:32
  • all the buttons are coming through this line - <apex:dynamicComponent componentValue="{!dynamicForm}"/>
    – Samir
    Jan 19, 2016 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .