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
Nick KeehanNick Keehan 

VF page - Search and edit Cases - Not updating/showing cases correctly

Hi Everyone.

Hope someone can help.

Looking to have a Search and Edit VF page for cases. I have modified a Jeffdouglas code to work with cases (SEE-  http://blog.jeffdouglas.com/2010/04/07/easily-search-and-edit-records-with-visualforce/ ) however when searching and bringing up a record it doesnt show the Case number, Picklist values from the case, and doesnt populate the case with new details.
It does "Edit" the case as it shows that i last modified by me, however doesnt update the case fields.

Heres My Code

VF PAGE
<apex:page standardController="Case" extensions="ItemEditController">  
  <apex:sectionHeader title="{!Case.CaseNumber}" subtitle="Case Search and Edit"/>
  <apex:form >
    <apex:pageBlock mode="edit" id="block">

      <apex:pageBlockButtons location="both">
        <apex:commandButton action="{!save}" value="Save Records"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
      <apex:pageMessages />

      <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
          <apex:outputLabel for="searchText">Case Number</apex:outputLabel>
          <apex:panelGroup >
          <apex:inputText id="searchText" value="{!searchText}"/>
          <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>
          </apex:panelGroup>
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection><br/>

      <apex:actionStatus id="status" startText="Searching... please wait..."/>
      <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1">
        <apex:pageBlockTable value="{!searchResults}" var="item" rendered="{!NOT(ISNULL(searchResults))}">
          <apex:column value="{!Case.CaseNumber}" headerValue="Item" width="100"/>
          <apex:column headerValue="Value" width="200">
            <apex:inputField value="{!Case.Description}"/>
          </apex:column>
          <apex:column headerValue="Value" width="200">
            <apex:inputField value="{!Case.Referral_Status__c}"/>
          </apex:column>
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Controller
public with sharing class ItemEditController {

  private ApexPages.StandardController controller {get; set;}
  public List<Case> searchResults {get;set;}
  public string searchText {get;set;}

  // standard controller - could also just use custom controller
  public ItemEditController(ApexPages.StandardController controller) { }

  // fired when the search button is clicked
  public PageReference search() {
    String qry = 'select id, CaseNumber, Referral_Status__c, Description from Case ' +
      'where Case.CaseNumber LIKE \'%'+searchText+'%\' order by Case.CaseNumber';
    searchResults = Database.query(qry);
    return null;
  }

  // fired when the save records button is clicked
  public PageReference save() {

    try {
      update searchResults;
    } Catch (DMLException e) {
      ApexPages.addMessages(e);
      return null;
    }

    return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
  }

  // takes user back to main record
  public PageReference cancel() {
    return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
  }

}

Missing Case number, and no pick list options.
User-added image

Modified by me, however no fields have been updated
User-added image

Any help would be apreciated.

Nick
Best Answer chosen by Nick Keehan
Rajiv Penagonda 12Rajiv Penagonda 12
Nick, there appears to be a bug in your VF page. You need to use the variable "item" that you have defined in line 24 of your VF page in the lines 25, 27 and 30. Your updated code should look like:
<apex:column value="{!Item.CaseNumber}" headerValue="Item" width="100" />
<apex:column headerValue="Value" width="200">
	<apex:inputField value="{!Item.Description}"/>
</apex:column>
<apex:column headerValue="Value" width="200">
	<apex:inputField value="{!Item.Referral_Status__c}"/>
</apex:column>

Hope this helps.

All Answers

Rajiv Penagonda 12Rajiv Penagonda 12
Nick, there appears to be a bug in your VF page. You need to use the variable "item" that you have defined in line 24 of your VF page in the lines 25, 27 and 30. Your updated code should look like:
<apex:column value="{!Item.CaseNumber}" headerValue="Item" width="100" />
<apex:column headerValue="Value" width="200">
	<apex:inputField value="{!Item.Description}"/>
</apex:column>
<apex:column headerValue="Value" width="200">
	<apex:inputField value="{!Item.Referral_Status__c}"/>
</apex:column>

Hope this helps.
This was selected as the best answer
Nick KeehanNick Keehan
Thanks Rajiv.

This worked perfectly.  Still have an issue with the finished url. Seems to go to .com/null instead of the record. any chance you know how to correct this. Thanks for your help again.

Nick
 
Rajiv Penagonda 12Rajiv Penagonda 12
Nick, you can update the Save and Cancel functions to return the following. This will take control to the Lead tab once either operation is completed.
 
return new PageReference('/00Q/o');

I am guessing currently in your code, for some reason, ApexPages.currentPage().getParameters().get('id') is returning null.