TransWikia.com

save button not working on pageblockTable column

Salesforce Asked by curiousCaseOfSfdc on October 4, 2021

I have added inlineEditSupport and save function to pageblocktable on Case object.
I want to save values in inputField "Case Review Notes" field (Case_Comments_On_VFReport__c). When I click on Save button, it does save value, but only on UI. When I refresh page, value is gone. Also when I tried to query Case_Comments_On_VFReport__c in devconsole I don’t see any update on this field.

Can you guys please help me here with code?

Visualforce Page

<apex:page controller="VF_CaseSearch" action="{!searchCase}" tabStyle="Case" sidebar="false">
    <apex:form >
        <apex:pageBlock>

            <apex:pageblockSection >
                <apex:inputText value="{!cas.CaseNumber}" label="Search Case Number"/>
            </apex:pageblockSection>
            
            <!---Search Button--> 
            <apex:pageblockButtons location="bottom">
                <apex:commandButton value="Search" action="{!searchCase}"/>
            </apex:pageblockButtons>
            </apex:pageBlock>
 
        <apex:pageBlock title="Case Details" id="details" rendered="{! IF( caseList != null && caseList.size >0, true, false)}" mode="edit">
            <apex:pageBlockTable value="{!caseList}" var="c">  
                <apex:column value="{!c.CaseNumber}" headerValue="Case Number"/>
                <apex:column value="{!c.CreatedDate}" headerValue="Created Date"/> 
                <apex:column value="{!c.Status}" headerValue="Status"/>
                <apex:column value="{!c.Severity__c}" headerValue="Priority"/>
                <apex:column headerValue="Case Review Notes">
                    <apex:inputField value="{!c.Case_Comments_On_VFReport__c}" />
                </apex:column>
            </apex:pageBlockTable>
           <apex:inlineEditSupport />
            
                    <!---Save Button -->
                    <apex:pageBlockButtons html-align="left" location="top">
                          <apex:commandButton value="Save" action="{!save}" />
                    </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Custom Controller

public with sharing class VF_CaseSearch {

  public Case cas{get;set;}
  public List<Case> caseList {get;set;}
  List<string> conditions = new List<string>();
  
    public VF_CaseSearch(){
      cas = new Case();
  }
  
  public void searchCase(){
      if(caseList !=null && caseList.size()>0){
          caseList=null;
      }
      searchCases ();
      conditions.clear();
  }
  
  
  public Void searchCases(){
      if(caseList != null && !caseList.isEmpty()){
          caseList.clear();
      }

      //create a dynamic query for filter results
      String strQuery ='SELECT Id, CaseNumber, CreatedDate, Status, Severity__c, Case_Comments_On_VFReport__c, FROM Case';
    
      if(cas.CaseNumber !=null && cas.CaseNumber !=''){
          conditions.add('CaseNumber Like'%' +cas.CaseNumber +'%' ');
      }
           
      if (conditions.size() > 0) {
          strQuery += '  WHERE  ' + conditions[0];
          for (Integer i = 1; i < conditions.size(); i++)
              strQuery += '  AND  ' + conditions[i];
      }
      
      caseList = Database.query(strQuery);
  }
    
     // Save button
     public PageReference save(){
        try{
            Database.update(caseList);
            system.debug('caseList'+ caseList);
            return ApexPages.CurrentPage();
        }
        catch(DMLException e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,e.getMessage()));
        }
        return null;
    }
}

One Answer

For anyone in future looking for answer, here is what I did after receiving a suggestion from Salesforce Developer Forum. Remove comma before FROM and add "false" to Database.update(caseList, false).

Correct answer by curiousCaseOfSfdc on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP