+ Start a Discussion
DeveloperSudDeveloperSud 

Visualforce Page: Redirect back to search result after clicking 'Back To Cases' link.

Hi Guys,
Need your help on the below situation.
I have a page which is showing "List of Cases" for my organisation.I have added a filter 'Status' so that it can refine the case list based on requirement.Status options are 'New' and 'Resolved' Cases and after choosing any one of the option if I hit the search button it will show the list of cases based on the status.If no option is selected by default it will show the all cases in the list.
Now the requirement is if I apply case filter status as 'new' and if it retuns 4 cases, after clciking any one of that case it should redirect to the case detail page and after clicking the 'back to cases' command link in case detail page it should redirect back to refined serach result (it should show all that 4 cases in the list not all the cases) .I am giving my code here .Please help .thanks!!!
<apex:page controller="testController100">
<apex:form >
<apex:outputPanel >
  <apex:pageBlock title="List Of Cases For My Test Organisation" >
    <apex:outputLabel ><b> Status : </b></apex:outputLabel>
       <apex:selectList value="{!caseStatus1}" size="1">
         <apex:selectOption itemvalue="NEW" />
         <apex:selectOption itemvalue="RESOLVED" />
       </apex:selectList>  
       <apex:commandButton value="search" action="{!search}" /> 
  </apex:pageBlock>
 </apex:outputPanel>    
 </apex:form>
 <!--show the List of Cases -->   
    <apex:form >
    <apex:outputPanel id="out1">
     <apex:pageBlock >
          <apex:pageBlockTable value="{!listofcases}" var="lstofcases">
           <apex:column >
             <apex:facet name="header" >
                <apex:commandLink value="Case" >   
            </apex:commandLink>             
          </apex:facet>  
        <apex:outputLink value="/apex/casedetail?id={!lstofCases.Id}" id="theLink0" >{!lstofcases.CaseNumber}</apex:outputLink> 
        </apex:column>
 
public with sharing class testController100 {
  
  public String caseStatus1{get;set;}
  
  public pagereference search(){ 
  return null;
  }
 
    // code to show list of cases
     public List<case> getlistofcases(){
      List<Case> listofcases=New List<Case>();
      if(caseStatus1=='NEW'){
      listofcases=[select casenumber,status,priority from case where status='New' order by status ASC];
     }
     else if(caseStatus1=='Resolved'){
     listofcases=[select casenumber,status,priority from case where status='Closed' order by status ASC];
     }
     else{
      listofcases=[select casenumber,status,priority from case where status='Closed' or status='New' order by status ASC];
     }
     return listofcases;
     }
    }
 
<!-- Case detail page-->
<apex:page standardController="case" extensions="testcontroller101">
<apex:form >
  <apex:outputpanel style="left-padding:600px" id="panelId">
            <apex:commandLink value="Back To Case" style="color:blue ;font-size:16px" action="{!backurl}" />
            <apex:pageBlock >
             <apex:pageBlockSection columns="2">
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Case #</apex:outputLabel>
                <apex:outputField value="{!CaseInfo.CaseNumber}" style="width:200px;"  id="BCname"/>
            </apex:pageBlockSectionItem>        
            <apex:pageBlockSectionItem >        
                <apex:outputLabel >Status</apex:outputLabel>
                <apex:outputField value="{!CaseInfo.Status}" style="width:200px;" id="CCategory"/>
            </apex:pageBlockSectionItem>
            </apex:pageblocksection>
            </apex:pageBlock>
  </apex:outputPanel>          
</apex:form>            
</apex:page>
 
public with sharing class testcontroller101 {

    public id caseId{get;set;}
    public Case CaseInfo { get; set; }
    
    public testcontroller101(ApexPages.StandardController stdController) 
    {
    caseId = stdController.getRecord().Id;
    if(caseId!=null)
        {
            CaseInfo=[ select casenumber,Id,status 
                  From Case where id=:caseId];
                  
            system.debug('--CaseInfo--'+CaseInfo);
}
}
   public pagereference backUrl()
    {
        pagereference pg=new pagereference('/apex/page10');
        return pg;
    }
}

 
Best Answer chosen by DeveloperSud
Virendra ChouhanVirendra Chouhan
Ok got it.
So you can send from and to date as a parameter of case Detail page:
<apex:outputLink value="/apex/casedetail?id={!lstofCases.Id}&fDate=fDateVariableName&tDate=tDateVariableName" id="theLink0" >{!lstofcases.CaseNumber}</apex:outputLink>
and in your casedetail page:
public pagereference backUrl()
    {
String fDateParam = apexpages.currentpage().getparameters().get('fDate');
String tDateParam = apexpages.currentpage().getparameters().get('tDate'
        pagereference pg=new pagereference('/apex/page10?status='+CaseInfo.status+'&fDate='+fDateParam+'&tDate='+tDateParam);
        return pg;
    }


 

All Answers

Virendra ChouhanVirendra Chouhan
Hello,

In the above senario while clicking on "beck to Case" link the filter will vanish, because the "caseStatus1" variable has no value and the else part will execute which query all the cases.

So for now you can use URL parameters to achive you requirnment for that some changes required:
Create a constructor on testController100 Class which will used to check if url parameter has some value or not if yes then set it to "CaseStatus1" variable.
public testController100(){
String statusParam = apexpages.currentpage().getparameters().get('status');
if(statusParam != null && statusParam != '')
   caseStatus1 = statusParam;
}
and some chages needed on your caseDetail page's controller, Just add one parameter on returnUrl :
public pagereference backUrl()
    {
        pagereference pg=new pagereference('/apex/page10?status='+CaseInfo.status);
        return pg;
    }



 
DeveloperSudDeveloperSud
Hi Virendra,
Thanks for your quick response.The code is working only when I am changing the status to ' New' not for 'Resolved'. I have changed in controller like below to fix this. Now can u pls tell me how to fix the issue if I add one more filter here. Please find my code below I have added a date range filter here.
public testController100(){
String statusParam = apexpages.currentpage().getparameters().get('status');
 system.debug('status is ' +statusParam);
if(statusParam != null && statusParam != '')
   if(statusParam =='Closed'){
   caseStatus1='RESOLVED';
   }
   else
   caseStatus1 = statusParam;
}

<apex:page controller="testController100" docType="HTML-5.0">
<apex:form >
<apex:outputPanel >
  <apex:pageBlock title="List Of Cases For My Test Organisation" >
    <apex:outputLabel ><b> Status : </b></apex:outputLabel>
       <apex:selectList value="{!caseStatus1}" size="1">
         <apex:selectOption itemvalue="NEW" />
         <apex:selectOption itemvalue="RESOLVED" />
       </apex:selectList>  
    <apex:outputLabel > <b>Date Range*:</b></apex:outputLabel> 
                        <apex:input label="datePicker" value="{! fDate }" type="auto"/>
    <apex:outputLabel > <b>To:</b></apex:outputLabel>           
                        <apex:input label="datePicker" value="{! tDate }" type="auto"/>
       <apex:commandButton value="search" action="{!search}" /> 
  </apex:pageBlock>
 </apex:outputPanel>    
 </apex:form>
 <!--show the List of Cases -->   
    <apex:form >
    <apex:outputPanel id="out1">
     <apex:pageBlock >
          <apex:pageBlockTable value="{!listofcases}" var="lstofcases">
           <apex:column >
             <apex:facet name="header" >
                <apex:commandLink value="Case" >   
            </apex:commandLink>             
          </apex:facet>  
        <apex:outputLink value="/apex/casedetail?id={!lstofCases.Id}" id="theLink0" >{!lstofcases.CaseNumber}</apex:outputLink> 
        </apex:column> 
          <apex:column >
             <apex:facet name="header" >
                <apex:commandLink value="Status">      
            </apex:commandLink>             
          </apex:facet>  
         {!lstofcases.Status}
        </apex:column>
          <apex:column >
             <apex:facet name="header" >
                <apex:commandLink value="Priority">    
            </apex:commandLink>             
          </apex:facet>  
         {!lstofcases.Priority}
        </apex:column> 
        <apex:column >
             <apex:facet name="header" >
                <apex:commandLink value="Open Date">    
            </apex:commandLink>             
          </apex:facet>  
         {!lstofcases.CreatedDate }
        </apex:column>   
      </apex:pageBlockTable> 
     </apex:pageBlock>
    </apex:outputPanel>
    </apex:form>
</apex:page>

 
Virendra ChouhanVirendra Chouhan
Hi,

Add another parameter in url like:
public pagereference backUrl()
    {
        pagereference pg=new pagereference('/apex/page10?status='+CaseInfo.status+'&fDate='+fDateValue+'&tDate='+tDateValue);
        return pg;
    }
and get the parameter value same as we did for status:
 
String statusParam = apexpages.currentpage().getparameters().get('status');
String fDateParam = apexpages.currentpage().getparameters().get('fDate');
String tDateParam = apexpages.currentpage().getparameters().get('tDate');


 
DeveloperSudDeveloperSud
Hi Virendra,
Here 'fDateValue' and 'tDateValue' both are using case 'createdDate' field value. so when redirecting back to List of cases page 'Date Range*' is taking the same value as 'To' date field.can u pls help how the the field value of 'date range' can be kept same?
Virendra ChouhanVirendra Chouhan
Ok got it.
So you can send from and to date as a parameter of case Detail page:
<apex:outputLink value="/apex/casedetail?id={!lstofCases.Id}&fDate=fDateVariableName&tDate=tDateVariableName" id="theLink0" >{!lstofcases.CaseNumber}</apex:outputLink>
and in your casedetail page:
public pagereference backUrl()
    {
String fDateParam = apexpages.currentpage().getparameters().get('fDate');
String tDateParam = apexpages.currentpage().getparameters().get('tDate'
        pagereference pg=new pagereference('/apex/page10?status='+CaseInfo.status+'&fDate='+fDateParam+'&tDate='+tDateParam);
        return pg;
    }


 
This was selected as the best answer
DeveloperSudDeveloperSud
Hi Virendra,
Thanks a lot. This is working now .
Virendra ChouhanVirendra Chouhan
No problem, glad you got it working.