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
Ramesh Rage 16Ramesh Rage 16 

Page Redirect (Cancel Button) is not working when system error was present in custom VF Page

Hi All,

I ahve encontered  strange in VF page, whcih i have never seen and also didnt find any help pnlinr for the issue. Pleas ehsrae your thoughts and ideas.

I have a custom VF page for Community users for capturing forecast volumes for next 2 years with Save Cancel and upload funtions, so for capturing forecast volume i have used apex InputFiled with Number datatype with (6,0) . But when users enters volume more than 6 numbers and tries to save, system shows error as expected "Number too large". So far it is ok. But when user cliks on "cancel" button to redirect to hompage, it doens't working. It still stays in the same page, with message "Number is too large".

Genrally when user clicks on cancel, cancel actions has to be executed, but in my page cancel method is not getting executed. i have kept debuig logs to check the same but it's not shopwing any debug logs when user clicks on cancel eventhiugh page gets refreshed.

Please share if am missing anyhing here..if you need more information on the issue.
GauravGargGauravGarg
Could you please share teh code.
Ramesh Rage 16Ramesh Rage 16
Hi Gaurav,

Here is my code.

<apex:page controller="ForecastSubmissionBySUUsers" showheader="False" docType="html-5.0">
   <apex:pageMessages id="Messages" />
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
   <script>
  
      
      <!-- Added by Ramesh to get user confirmation while submitting forecast -->
      function confirmSubmit() {
              return confirm('Are you sure you want to submit this Forecast?');
       }
       <!-- Added by Ramesh to prevent forecast submit on Carriage retunr <ENTER>  -->
      function ignoreEnterKey(e){
          if ((window.event&&window.event.keyCode==13) || e.which==13) {
              return false;
          } else {
              return true;
          };
      } 
      
      function showCSV()
      {
             <!--  $(".hiddenDiv").show(); -->
               
           $(".hiddenDiv").slideToggle("slow", function() {
         
        });
                   
        
      }
         window.onload=function()    
         {   
             $(".hiddenDiv").hide();
             if({!continueFlag}===true && {!isSuApproved}===false)
             {
                           if(confirm("Forecast is already submitted for this month.Please click on ‘Ok’ button if you still want to continue to update the existing current month Forecast  else click on ‘Cancel’ button"))
                                   return false;
                           else
                                 goback();
             }
             if({!isSuApproved}===true)
             {
                 alert('Records cannot be edited after the last commit date');
             }
        }
      function sample(a)
      {
              alert('------');
      }
    
      function calculate1(total,old,current)
      {
                   if(!document.getElementById(current).value)
                                  document.getElementById(current).value=0; 
                                  
                  var oldvalue=document.getElementById(old).innerHTML.replace(',','');
                  var currentvalue=document.getElementById(current).value.replace(',','');
                  var toatalvar=document.getElementById(total).innerHTML.replace(',','');

                  if(isNaN(currentvalue))
                  {
                           alert('Please enter only Numbers');
                           document.getElementById(current).style.color = "Red";
                           document.getElementById(current).style.borderColor = "Red";
                  }
                  else
                  {                                    
                              if(currentvalue>0 && currentvalue<896)
                              {
                                  alert('Quantity of Unit is less than One Pallet');
                                  document.getElementById(current).style.color = "Red";
                                  document.getElementById(current).style.borderColor = "Red";
                              }
                              else
                              {
                                  document.getElementById(current).style.color = "Black";
                                  document.getElementById(current).style.borderColor = "initial";
                                  var v=parseInt(toatalvar) - parseInt(oldvalue)  + parseInt(currentvalue);
                                  document.getElementById(total).innerHTML= v;
                                  var gtot= parseInt(currentvalue);
                                  document.getElementById(old).innerHTML=gtot;
                              }
                              
                  }
      }
      
       function limitfieldvalue(field){
        if(document.getElementById(field).value.length > 5){
            alert('not allowed more than 5 digits');
            
        }
    }
   </script>
   <script>
    jQuery( document ).ready(function( $ ) {
       var max =6;
        $(".equipCatValidation").on('keyup', function(e){           
             if (e.which < 0x20) {
                 return;
             }
            if (this.value.length == max){
                e.preventDefault();
                $(this).addClass('maxQuantity').focus();
            }else if (this.value.length > max) {
                // Maximum exceeded
                this.value = this.value.substring(0, max);
            }
         });
      });
   </script>
   <style>
       .maxQuantity:focus{
            border-color: red;
        }
   </style>
   <apex:form >
      <apex:actionFunction name="goback" action="{!goback}"/>
      <table class="arq-table" border="1">
         <tr>
            <td bgcolor="#53B3AE">SU Forecast Reference</td>
            <td>
               <apex:outputfield value="{!suReference.Name}"/>
            </td>
         </tr>
         <tr>
            <td bgcolor="#53B3AE"> SU Forecast Date</td>
            <td>
               <apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
                  <apex:param value="{!suReference.lastmodifieddate}" />
               </apex:outputText>
            </td>
         </tr>
      </table>
      <br/> <br/>
      <!--  <div class="bs">  -->
      <!-- <table border="1" width="60%"> -->
      <table class="arq-table" border="1">
         <th bgcolor="#53B3AE"> Delivery Months</th>
         <apex:repeat value="{!ccproductlist}" var="p">
            <th bgcolor="#53B3AE"> {!p.Name} <br/>({!p.ccrz__SKU__c}) </th>
         </apex:repeat>
         <th bgcolor="#53B3AE"> Total Quantity </th>
         <apex:variable value="{!0}" var="rowNum"/>
         <apex:repeat value="{!fieldNames}" var="f">
            <tr>
               <apex:variable value="{!0}" var="TotalNum"/>
               <td>
                  <apex:outputText value="{0, date, MMM - YYYY}">
                     <apex:param value="{!datelist[rowNum]}"/>
                  </apex:outputText>
                  <apex:variable var="rowNum" value="{!rowNum + 1}"/>
               </td>
               <apex:repeat value="{!ccproductlist}" var="p">
                  <apex:repeat value="{!PRodMap[p.ccrz__SKU__c]}" var="mapList" id="entirerow" >
                     <!-- <apex:repeat value="{!mapList}" var="listElement" rows="0"> -->   
                     
                                 
                     <td style="display:none">
                        <apex:outputPanel >   
                        <apex:outputfield value="{!mapList[f]}" id="oldvalue" />   
                        </apex:outputPanel> 
                      </td>
                      <td >
                        <apex:inputfield html-size="6" value="{!mapList[f]}" styleClass="equipCatValidation"  onfocus="this.oldvalue = this.value;" id="varient"  rendered="{!NOT(IF(isSUApproved=TRUE,true,false) || IF(f='arq_quantityofmonth1__c',true,false) || IF(f='arq_quantityofmonth2__c',true,false) || IF(f='arq_quantityofmonth3__c',true,false) || IF(f='arq_quantityofmonth4__c',true,false) || IF(f='arq_quantityofmonth5__c',true,false) )}"   style="color:{!IF(AND(mapList[f]<896,mapList[f]>0),'red','initial')};border-color:{!IF(AND(mapList[f]<896,mapList[f]>0),'red','initial')};width:100%"  onchange="calculate1('{!$Component.total}','{!$Component.oldvalue}',this.id);" />
                        <apex:outputfield value="{!mapList[f]}" rendered="{!OR(isSUApproved,IF(f='arq_quantityofmonth1__c',true,false) || IF(f='arq_quantityofmonth2__c',true,false) || IF(f='arq_quantityofmonth3__c',true,false) || IF(f='arq_quantityofmonth4__c',true,false) || IF(f='arq_quantityofmonth5__c',true,false) )}" >
                        </apex:outputfield>

                     </td>
                     
                      <apex:variable var="TotalNum" value="{!TotalNum + mapList[f]}" />
                     <!--   </apex:repeat>    -->
                  </apex:repeat>
               </apex:repeat>
               <td >
                  <apex:outputText id="total" value="{0, number, ###,###,###,##0}">
                     <apex:param value="{!TotalNum}"/>
                  </apex:outputText>
               </td>
            </tr>
         </apex:repeat>
      </table>
      <br/>
      <!--     <apex:outputtext value="Upload CSV"  html-ng-click="changeShow()"  styleclass="btn btn-primary"/> -->
      <apex:outputPanel rendered="{!!isSuApproved}">
         <apex:commandButton value="Submit Forecast" action="{!submitForecast}"  styleclass="submit" onclick="return confirmSubmit();"/>
         &nbsp;&nbsp;
         <apex:commandButton value="Cancel" action="{!goback}"/>
         &nbsp;&nbsp;
         <button type="button"  class="btn" value="Upload" onclick="showCSV();">Upload CSV</button>
      </apex:outputPanel>
      <!--       </div>  -->
      <div class="hiddenDiv">
         <fieldset>
            <legend style="color:black;font-weight:bold;">Upload</legend>
            <br/>
            <br/> 
            <apex:inputFile id="file" value="{!contentFile}" alt="Choose CSV" filename="{!nameFile}" accept=".csv" contentType="{!type}"/>
            <apex:commandButton value="Upload"  action="{!ReadFile}"  id="theButton" onclick=" return checkFileType('{!$Component.file}');"/>
            <br/> <br/> 
            <font color="black"> Note: Please use the standard template to upload Forecast Records <a href="{!URLFOR($Resource.ArqivaForecastCSVTemplate)}" target="_blank" style="color:blue;"> Click here </a> to download the template </font>
         </fieldset>
      </div>
   </apex:form>
   <br/><br/>
</apex:page>

Controller code for Cancel button.
 public PageReference goback() {
                    PageReference pg = new PageReference('/ArqivaESales/ccrz__HomePage');
                    system.debug(' Came here ='+pg);
                    pg.setRedirect(true);
                    return pg;
                }


let me know if need whole controller code.
Ramesh Rage 16Ramesh Rage 16
Hi Gurav,

Thanks for the response.

Actually Input Number field which i have used in the UI has digits (6,0) limit in the object, but in the UI it gives the user a chance to enter more than 6 digits but while saving record the system is thworing error. Till here it going as expected.

But when user tries to go back using cancel button, cancel redirect is not worling. I eevn checked debug log, cancel action wasn't triggered at all in this situation. Not sure whats going wrong here. Also not sure is this standard was of VF page responce.

Pleas eshare your thoughts.

Thank you.
GauravGargGauravGarg
Ramesh,

Try writing custom cancel button code
 
Public PageReference custom_Cancel(){
  PageReference pr = new PageReference(Apexpages.currentPage().getParameter().get('Id'));
pr.setRedirect(True);

return pr;
}

Hope this helps.

Thanks,
Gaurav