0

I have a silly problem but I'm not able to find a solution. I have a VF page inside a record detail page. Inside the VF page I have a command button. At the end of the function inside the button action I want that the record detail page is reloaded. If I set "return null" or "return Apex.Currentpage()",solely the VF page is reloaded, not the entire page . How can I solve this issue? Thank you (below the code)

VF page inside the detail record page (section)

</apex:page>    
<apex:pageMessages />
    <apex:form styleClass="formstyle" >
    <div class='leftLabelColumn' style="margin-left:10px">
    <apex:param name="plId" value="{!P_L__c.id}" />
    </div>
    <div class='middleLabelColumn' style="margin-left:20px">
    </div>
    <div class='righLabelColumn' style="margin-right:-20px" >
    <apex:commandButton id="calc2" action="{!calc}" value="Calculate"/>
    </div>
    [cal is the function I mentioned...... ]
    </tr>
    </table> 
    </div>
    </apex:form>
    </apex:page>

and the controller function

public pagereference calc(){
     System.debug('calculate');
     Decimal appoggio;
     //this function when you impose a target revenue calculate the extra discount needed to reach it
     P_L__c p = [select id,TargetMatRevenue__c,TargetSerRecRevenue__c,TargetServNotRecRevenue__c               
                from P_L__c where id=:pl.id];
    System.debug('pel '+ p);
    //first step ......update the target revenue with the values inserted
    p.TargetMatRevenue__c=pl.TargetMatRevenue__c;
    p.TargetSerRecRevenue__c=pl.TargetSerRecRevenue__c;
    p.TargetServNotRecRevenue__c=pl.TargetServNotRecRevenue__c;
    update p;
     return null;
    }

N.B. The code is too long I simply it it.

1 Answer 1

1

Try returning void in your calc() method and refresh the page using javascript.

On the button onclick atribute call a javascript function to do a window location on your current visualforce page, like:

window.open("/apex/Your_VF_Page","_self");`. 

This should do the trick.

3
  • Also would be better to add rerender for command button, which would avoid page refresh.
    – Raul
    Commented Oct 25, 2016 at 9:59
  • Yes to avoid calling the page twice, true. But you should only do this if you really need to rerun the controllers constructor. Else just rerender your page.
    – user37586
    Commented Oct 25, 2016 at 10:11
  • i use this :<script> function ricarica(){ window.open('/apex/P_Lprepage?id={!P_L__c.id}','_self'); } </script>For my purpose I need to reload the entire page.Thank you Commented Oct 25, 2016 at 10:47

You must log in to answer this question.

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