0

I have written two method cancel and save.Both methods are redirecting me to case page. Only difference is my save method save the object first and den the redirect happens.

When i clicking the save button.records get inserted into my custom account but it fails to redirect to case page..

Below is the code :

public PageReference btnCancel() {
       PageReference pgRef = new pagereference('/'+caseid);
       pgRef.setRedirect(true);
       return  pgRef;
    }

    public Pagereference saveRecord() 
    {

       ObjRMAreturn = new RMA_Return__c(case__c = caseid, Serial_Number__c = objRMAProductInfo.Serial_Number__c ,Description__c =objRMAProductInfo.Description__c , Product__c= objRMAProductInfo.Product__c  );
       Insert ObjRMAreturn ;
       system.debug('abcde1');
       Pagereference Pagref = new Pagereference('/'+caseid);
       system.debug('abcde2');
       Pagref.setredirect(true);
       system.debug('abcde3');
       return Pagref;

    }

In debug i have checked.Its not showing any error. Please help

My vf Page

<apex:form >
      <div style="height:43px; background-color:white">
         <br/>
         <h3 style="font-size: large;">
            ADD PRODUCT
         </h3>
      </div>
      <apex:pageBlock >
         <table width="100%"  >
            <tr>
               <td width = "70%">
                  <table width="100%" >
                     <tr>
                        <td>
                           <fieldset>
                              <legend>Product/Device:</legend>
                              <apex:pageBlockSection columns="2" >
                                 <apex:inputText label="Serial Number" value="{!serialNo}"/>
                                 <apex:commandButton value="Find Product" action="{!findProducts}" rerender="popup" status="status"/>
                              </apex:pageBlockSection>
                           </fieldset>
                        </td>
                     </tr>
                     <apex:outputPanel rendered="{!hideShowProductDetails}">
                     <tr>
                        <td>

                          <fieldset>
                              <legend>Product Details:</legend>
                              <apex:pageBlockSection columns="1" >
                                 <apex:outputText value="{!objRMAProductInfo.Product__r.name}"/>
                                 <apex:outputText value="{!objRMAProductInfo.Serial_Number__c}"/> 
                                 <apex:outputText value="{!objRMAProductInfo.Description__c}"/>
                                 <apex:outputText value="{!objRMAProductInfo.RMA_Service_Entitlement__c}"></apex:outputText>
                                 <apex:outputtext value="{!ContactInfo}">Contact Info ::</apex:outputtext>
                                 <apex:outputtext value="{!BillingInfo }">Billing Info ::</apex:outputtext>
                                 <apex:outputtext value="{!WarrantyInfo }">Warranty Info::</apex:outputtext>
                                 <apex:outputtext >Site Info::</apex:outputtext>
                                 <apex:inputCheckbox label="I want to make updates to above information"/>
<!-- //TODO :: order of field name Map it                   
Product Number   
Product Description 
Warranty Info   
Contract Info   
Site Info   
Contact 
Billing Info    
Service Entitlement
--> 
                            </apex:pageBlockSection>

                           </fieldset> 
                        </td>
                     </tr>

                     <tr>
                        <td>
                            <fieldset>
                              <legend>Problem:</legend>
                              <apex:pageBlockSection columns="2" >
                              <apex:inputField value="{!objRMAProductInfo.RMA_Problem_Code_1__c}"/>
                              <apex:inputField value="{!objRMAProductInfo.RMA_Problem_Code_2__c}"/>
                              <apex:inputField value="{!objRMAProductInfo.Problem_Description__c}"/>

                              </apex:pageBlockSection>
                           </fieldset>
                        </td>
                     </tr>
                      </apex:outputPanel>
                  </table>
               </td>
               <td width= "30%"  valign="top">
                  <table width="100%" >
                     <tr>
                        <td>
                            <fieldset>
                              <legend>Cart:{!Intcartsize}</legend>
                              <apex:pageBlockSection columns="1" >
                                  <apex:repeat value="{!lstcart}" var="cartlist">
                                       {!cartlist.Serial_Number__c}<br/>
                                    </apex:repeat>
                               </apex:pageBlockSection>
                           </fieldset>
                        </td>
                     </tr>

                  </table>
               </td>
            </tr>
         </table>
      </apex:pageBlock>
      <apex:pageBlock >
         <apex:outputPanel id="popup">
          <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
            <apex:outputPanel id="popInnerOutputPnl" styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
               <apex:commandButton value="X" title="Close the popup" action="{!closePopup}" styleClass="closeButton" rerender="popup">
               </apex:commandButton>

                  <apex:pageBlockTable value="{!lstRMA}" var="lstRMAvar" width="100%">
                     <apex:column headerValue="Serial Number">
                        <apex:outputLink value="/apex/ZEB_RMA_FindProduct?rmaSelId={!lstRMAvar.id}&caseId={!caseid}" >{!lstRMAvar.Serial_Number__c}</apex:outputLink>
                     </apex:column>
                     <apex:column value="{!lstRMAvar.Product__c}"/>
                     <apex:column value="{!lstRMAvar.Description__c}"/>
                     <apex:column value="{!lstRMAvar.Product_Name__c}"/>
                     <apex:column value="{!lstRMAvar.Product_Family__c}"/>
                  </apex:pageBlockTable>


            </apex:outputPanel>
         </apex:outputPanel>

            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Cancel" action="{!btnCancel}"/>
                 <apex:commandButton value="Save" action="{!saveRecord}"/>
            </apex:pageBlockButtons>
      </apex:pageBlock>
   </apex:form>
6
  • FYI RMA Return is a little redundant. Also you misspelled it.
    – Adrian Larson
    Jun 17, 2015 at 14:22
  • Yes.Please find the new edited code Jun 17, 2015 at 14:24
  • 1
    It would be helpfull to understand if you share your vf page code where you have created your save button. Jun 17, 2015 at 14:26
  • please find my vf page attached Jun 17, 2015 at 14:30
  • 2
    is ur developer mode enabled ?.. try to disable it and test it.
    – sfdc
    Jun 17, 2015 at 15:10

2 Answers 2

1

I don't see anything about your code that would cause it to not redirect, but I strongly recommend adding a try/catch around any DML you perform.

try
{
    insert RMA;
}
catch (DmlException dmx)
{
    ApexPages.addMessages(dmx);
    return null; // abort redirect so messages can be viewed
}

Additionally if you are redirecting via PageReference, I think it's more "best practice" to use StandardController methods.

Case returnCase = new Case(Id=caseId);
return new ApexPages.StandardController(returnCase).view();
7
  • but the same thing is working in cancel button method Jun 17, 2015 at 14:34
  • i tried ur suggestions..but its still not working Jun 17, 2015 at 15:12
  • As I said at the beginning of my answer, I see nothing wrong with your code snippets. The code you have posted does not lead to a reproducible result.
    – Adrian Larson
    Jun 17, 2015 at 15:15
  • i tried redirecting to diiferent pafe..but nothing works..if i remove the insert statement..its working then..do you have any suggestions? Jun 17, 2015 at 15:18
  • Anything funky going on with getters/setters on caseId?
    – Adrian Larson
    Jun 17, 2015 at 15:29
1

My developer mode was enabled.When i turned if off, redirecting works..I searched a lot and was not able to find a proper reason for it..but for now it works.

Still searching for the answer.will update once i get some positive reason for this

1
  • this happened to me as well. Bug in the platform Feb 16, 2017 at 16:24

You must log in to answer this question.

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