function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jina ChetiaJina Chetia 

Was there any change in the VisualForce core code- My pages are not working?

Hi,

I developed a wizard with VisualForce pages and everything was working perfectly fine till yesterday and today I find that most of my logic is falling and this is one thing that I noticed -

Since I am using the rendered attribute to hide and display sections depending on different condition, I need the Boolean flag in various methods of my controller to either true or false. In methods where I have set the flags and suppose that method does not return a Boolean, the logic is not working.
 
Say for example in Wizard Step 2
 
public Contract getContract()
    {
         Id contractId = System.currentPageReference().getParameters().get('Id');
         if(contract == null)
         {
             if(contractId == null)
             {
                 contract = new Contract();
             }
             else if(contractId != null)
             {
                contract = [select id, AccountId, StartDate, END_DT__c, ContractTerm, ADV_NOTICE__c,CRT_COM__c from Contract
                    where id = :contractId];
             }
        }
       
        return contract;
        //setButtonFlags();
    }
 In the above method getContract() I was calling the below method setButtonFlags() to set the various flags. As getContract() was the first method being called from the Controller by the page I was doing the initialization here but since  getContract() method does not return a Boolean the values were not getting set.
 
 
  /* Set the contractSummary and continue Button flags */
    public void setButtonFlags()
    {
          String contractSum = System.currentPageReference().getParameters().get('contractSum');
         if(contractSum != null && contractSum.equals('true'))
         {
             setContinueButton(false);
             setContractSummary(true);
        
         }
         else
         {
        
             setContinueButton(true);
             setContractSummary(false);
         }
       
   
    }
 
Then I called this method from the getContinueButton() and the code started working as this method returns Boolean.
 /* This is the getter method for continueButton flag */
    public Boolean getContinueButton()
    {
        setButtonFlags();
        return this.continueButton;
    }
 
This was just a simple example, I have noticed the same behaviour in all the other pages. I was wondering what went wrong with all the pages that were working perfectly fine till yesterday. I don't know whether this is bug which came out while solving something else or a newly introduced restriction.

Can anyone please let me know what is the issue?

Thanks
Jina

dchasmandchasman
Jina,

You should never rely on the order that getters/setters are invoked ("as getContract() was the first method being called from the Controller by the page") - there is not guaranteed order (never was) and writing code that relies on side effects inside of getters and setters is not a good idea.

Can you also post your page's markup - its very hard to follow statements like "In methods where I have set the flags and suppose that method does not return a Boolean, the logic is not working." w/out seeing how you are binding your components to your controller.

Also, I suspect that your pages/controller would be simplified greatly by using the standard controller in combination with a custom controller extension...


Jina ChetiaJina Chetia
Here is my piece of code-
Code:
Page
<apex:page id="pageForm" controller="Wizard_Step2_Controller">
  <apex:form id="form">
   <apex:pageBlock >
  <apex:actionFunction name="calEndDate" action="{!calEndDate}" />
  <h2> Please Enter Some General Information </h2>
  <p><span style="padding :10px;"/> Contract Effective Date : <span style="padding :12px;"/>
      <apex:inputField id="effectiveDt" value="{!contract.StartDate}">
          <script language="Javascript">
              function setFocusOnLoad() {} 
          </script>
      </apex:inputField>
  </p>
 
  <p> <span style="padding :23px;"/> Contract Duration : <span style="padding :12px;"/><apex:inputField id="duration" value="{!contract.ContractTerm}"/>
  <span style="padding:5px;"/> <apex:commandButton value="Calculate End Date" action="{!calEndDate}"></apex:commandButton></p>
  

  <p> <span style="padding :21px;"/> Contract End Date       :<span style="padding :14px;"/> <apex:outputField id="endDt" value="{!contract.END_DT__c}"/></p>
  <p> Advance notice to Merchant for </p>
  <span style="padding :13px;"/>Contract Cancellation :<span style="padding :15px;"/><apex:inputField id="contractCanDays" value="{!contract.ADV_NOTICE__c}"/>
  <p><span style="padding :5px;"/>Additional Comments about contract term/duration: </p>
  <p><span style="padding :25px;"/><apex:inputField id="Comments" style="height:100px;width:200px;overflow-y:scroll" value="{!contract.CRT_COM__c}"/></p>
  
  <p><span style="padding:100px;"/><apex:commandButton action="{!nextPage}" id="Continue" value="Continue" rendered="{!continueButton}"></apex:commandButton></p>
      <apex:outputPanel rendered="{!contractSummary}">
          <p><span style="padding:100px;"/><apex:commandButton action="{!save}"  value="Save"/><span style="padding:5px;"/>
              <apex:commandButton action="{!Cancel}" value="Cancel"/></p>
      </apex:outputPanel>
  </apex:pageBlock>
  
</apex:form>
</apex:page>

Controller:
/*
        This Apex class is the controller class for the Step 2 in the wizard. 
        This class contains methods for displaying the various sections of the page. 
*/
public class Wizard_Step2_Controller 
{

    /*
        The current Contract instance.  
    */
    Contract contract = null;
    
    /*
        The current Account instance. 
    */
    Account account =  null;
    
    /*Boolean value to display the Continue Button */
    Boolean continueButton = true;
    
    /*Boolean value to show Save and Cancel button */
    Boolean contractSummary = false;
    
    /*  
        This method is responsible for redirecting the user to the next page in the wizard i.e. Page3. 
        This method retrieves the contractId passed via a query string and inserts the contract instance 
        into the database if its a new contract that is created else updates the contract instance. 
    */
    public PageReference nextPage() 
    {
        PageReference pr = null;
       
        Id contractId = System.currentPageReference().getParameters().get('Id');
        if(contractId == null)
        {
            Account act = getAccount();
            RecordType recordType = getRecordType();
            setAccountId(act.id);
            setRecordTypeId(recordType.Id);
            insert contract;
           
        }
        else
        {
            update contract;
            
        }
       // String retURL = '/wizard_step2—accountId='+System.currentPageReference().getParameters().get('accountId');
        //retURL = retURL+'&contractId='+getContract().Id;
        pr = Page.Wizard_Step3;
        
        pr.getParameters().put('contractId', contract.Id);
       // pr.getParameters().put('retURL', retURL);
        pr.setredirect(true);
        return pr;
    }
    
    /*
        This method is responsible for retrieving the record type for DP Contract Record
        from the database. 
    */
    public RecordType getRecordType()
    {
        return [select id from RecordType where name='DP Contract Record'];
    }
    
    /*
        This is a setter method for the recordTypeId flag in the Contract instance.
    */
    public contract setRecordTypeId(Id recordId)
    {
        if(contract!= null)
        {
            contract.RecordTypeId = recordId;
        }
        return contract;
    }
    
    /*
        This method is responsible for returning back a relevant Contract instance for the 
        current transaction. It returns the Contract instance on the basis of a contractId passed 
        through a query string. If no contract is found for the contractId specified, this method
        returns a new Contract instance. 
    */
    public Contract getContract()
    {
         Id contractId = System.currentPageReference().getParameters().get('Id');
         if(contract == null)
         {
             if(contractId == null)
             {
                 contract = new Contract();
             }
             else if(contractId != null)
             {
                contract = [select id, AccountId, StartDate, END_DT__c, ContractTerm, ADV_NOTICE__c,CRT_COM__c from Contract
                    where id = :contractId];
             }
        }
        
        return contract;
    }
    
    /* Set the contractSummary and continue Button flags */
    public void setButtonFlags()
    {
          String contractSum = System.currentPageReference().getParameters().get('contractSum');
         if(contractSum != null && contractSum.equals('true'))
         {
             setContinueButton(false);
             setContractSummary(true);
         
         }
         else
         {
         
             setContinueButton(true);
             setContractSummary(false);
         }
        
    
    }
    
    /*
        This is a setter method for the accountId in the current Account instance.
    */
    public Contract setAccountId(Id accountId) 
    {
        if(contract!= null)
        {
            contract.AccountId = accountId;
        }
        return contract;
    }
    
     /*
        This method is responsible to retrieve an Account instance given its Id. 
        The Id is passed as a form element via the query string.    
     */
    public Account getAccount()
    {    
       if(account == null)
        {
            account = [select id, name from Account
                where id = :System.currentPageReference().getParameters().get('accountId')];
        }
        return account;
       
   }
   
   /* This method calculates the End Date depending on the Contract Effective Date 
     and Contract Duration */
    public PageReference calEndDate() 
    {
        Date dat = getContract().StartDate;
        Integer months = getContract().ContractTerm;  
        if(dat != null && months != null)
        {
            contract.END_DT__c = dat.addMonths(months);
           
        }
        
        return null;
    }
   
    /* This is the setter method for continueButton flag */
    public void setContinueButton(Boolean continueButton)
    {
    
        this.continueButton = continueButton;
    }
    /* This is the getter method for continueButton flag */
    public Boolean getContinueButton()
    {
        setButtonFlags();
        return this.continueButton;
    }
    
    /* This is the setter method for contractSummary flag */
    public void setContractSummary(Boolean contractSummary )
    {
    
        this.contractSummary = contractSummary ;
    }
    /* This is the getter method for contractSummary flag */
    public Boolean getContractSummary()
    {
    
        return this.contractSummary ;
    }
    
    /* This implements the save functionality */
    public PageReference Save()
    {
        update getContract();
        PageReference pr = Page.contract_summary;
        pr.getParameters().put('contractId', getContract().Id);
        pr.setredirect(true);
        return pr;
    
    }
    /* This method implements cancel functionality */
    public PageReference Cancel()
    {
        PageReference pr = Page.contract_summary;
        pr.getParameters().put('contractId', getContract().Id);
        pr.setredirect(true);
        return pr;
    
    }
}

 Even in the other pages where I set the Boolean flags in the getters of the method which does not return a Boolean fails. As these pages are called from different location and depending on different conditions I need to change the display of the page, so I am setting the flags on the getter methods instead of doing it on some action method.
Everything was working fine till yesterday and today it is failing. The code which I have pasted is one of my simple pages, there are much complex ones where I need to change a lot of display features. How to go about without putting the logic of setting other flags in getters?
How to use standard controller in combination with a custom controller extension...?

Thanks,
Jina