0

I have a button that updates an opportunity. When it is complete the page refreshes but doesn't reload with updated data here is my code:

Controller

 public class ContractDetails{
            public Opportunity ThisOpportunity{get;set;}  
            public string oppid {get;set;}
            public string requested {get;set;}

       public ContractDetails(){
            oppid = ApexPages.currentPage().getParameters().get('id');
            requested = ApexPages.currentPage().getParameters().get('requested');
            string selected = 'background-color:#4bca81;color:white';

            if(oppid==null){
                            oppid = ApexPages.currentPage().getParameters().get('oppidd');
       }
            ThisOpportunity = [Select Contract_Requested__c FROM Opportunity where ID=:oppid];
            if(ThisOpportunity.Contract_Requested__c == boolean.valueOf('true')){
                requested = selected;
            }
       }
       public void save(){
                    ThisOpportunity.Contract_Requested__c = boolean.valueOf('True');
                    system.debug(ThisOpportunity.Contract_Requested__c);
                    update ThisOpportunity;
       }

VFP:

<apex:page controller="ContractDetails"  showHeader="false" standardStylesheets="false" sidebar="false" docType="html-5.0" >
  <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <apex:slds />
  <script type="text/javascript">
            function requested(){
                    requestedoper();
                    }
            function rerender(){
                     window.location.href='/apex/TestPage?oppidd={!oppid}';
                    }
  </script>
  <apex:form id="wf">
  <button class="slds-badge" style="{!requested}" onclick="requested()">Requested
       <apex:actionfunction action="{!save}" name="requesteoper" oncomplete="rerender()"></apex:actionfunction></button></apex:form>
  </html>
  </apex:page>  

I would expect the {!requested} to be loaded with the selected variable on the reload, but it appears it doesn't rerun the sobject query in the main function.

How do I get this to rerun?

The page refreshes then runs the method in the controller in a separate operation, see log below: enter image description here

0

Your guess is right..

Since you are doing a partial load using action function and rerender and not reloading the entire page, your controllers constructor will not run and so the object is not getting reinitialised after the update.

you can move the initialization part into a helper method and call it from both the constructor and from the save method after updating the record.

|improve this answer|||||
  • So, when i click the button the page refreshes then in a separate operation runs the function in the method in the controller. I added an oncomplete to the apexactionfunction but it never performs it, shouldn't this be able to rerender the page? – AverageJoeVBA Jul 3 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.