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
sfdc@isha.ax1814sfdc@isha.ax1814 

standard save - on case status change display new fields and save

Hi team,

I have a vfpage design which holds the logic of based on the case status change new fields should be displayed and once value will be given and click on save values will be saved and fields should be non edit mode and should hike the save button as well


vfpage:

<apex:page standardController="Case" extensions="caseextension">
    
    <apex:form id="theForm">
        
        <apex:pageBlock mode="inlineEdit">
            <apex:pageblockSection >
                <apex:outputField value="{!Case.Status}">
                    <apex:actionSupport event="onchange" reRender="theForm"/>
                </apex:outputField>
            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageblock mode="inlineEdit">
       
            <apex:pageblockSection rendered="{!IF(Case.Status = 'Working' && rend,TRUE,FALSE)}">
                <apex:inputField value="{!Case.Working_1__c}"/>
                <apex:inputField value="{!Case.Working_2__c}"/>
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Case.Status = 'Escalated' && rend}">
                <apex:inputField value="{!Case.NewText1__c}"/>
                <apex:inputField value="{!Case.New_Text2__c}"/>
           
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Case.Status = 'Working' && rend1}">
                <apex:outputField value="{!Case.Working_1__c}"/>
                <apex:outputField value="{!Case.Working_2__c}"/>
            </apex:pageblockSection>
            
            <apex:pageblockbuttons>
                 <apex:commandButton value="Save" action="{!save}"/>
                 
            </apex:pageblockbuttons>
            
        </apex:pageblock>
    </apex:form>
</apex:page>


Class:

public class caseextension {

    private final Case caseObj;
    public boolean rend{get;set;}
    public boolean rend1{get;set;}

    // get Case record from the standard controller and putting it in a member variable
    public caseextension (ApexPages.StandardController stdController) {
        this.caseObj = (Case)stdController.getRecord();
        rend=true;
        rend1=false;
    }

    public  PageReference save(){
        // TO DO
        rend=false;
        rend1=true;
        
        insert caseObj;
           
        
        
     return null;

    }

}

Iam getting below error User-added image
Regards,
Isha
Dushyant SonwarDushyant Sonwar
Isha ,

You need to upsert dml operation if you are using same form for insert and update both.
 
public  PageReference save(){
        // TO DO
        rend=false;
        rend1=true;
        
        upsert caseObj;
           
        
        
     return null;

    }

 
sfdc@isha.ax1814sfdc@isha.ax1814
Hi Team,

After saving  fields should be in non edit mode. but in my req after saving fields are in still editable and textbox is appearing.

Can somene help me on this vfpage code.


User-added image



Regards,
Isha
Dushyant SonwarDushyant Sonwar
You need to use the rerender to hide/show your save button and fields.

To Do this

1) Create a boolean variable isSuccessfullySaved (default set value to false).

2)Use the variable like this as a below example.
 
public  PageReference save(){
        // TO DO
        rend=false;
        rend1=true;
        
        upsert caseObj;
           isSuccessfullySaved = true;
        
        
     return null;

    }

<apex:page standardController="Case" extensions="caseextension">
    
    <apex:form id="theForm">
        
        <apex:pageBlock mode="inlineEdit">
            <apex:pageblockSection >
                <apex:outputField value="{!Case.Status}">
                    <apex:actionSupport event="onchange" reRender="theForm"/>
                </apex:outputField>
            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageblock mode="inlineEdit">
       
            <apex:pageblockSection rendered="{!IF(Case.Status = 'Working' && rend,TRUE,FALSE)}">
                <apex:inputField value="{!Case.Working_1__c}"/>
                <apex:inputField value="{!Case.Working_2__c}"/>
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Case.Status = 'Escalated' && rend}">
                <apex:inputField value="{!Case.NewText1__c}"/>
                <apex:inputField value="{!Case.New_Text2__c}"/>
           
            </apex:pageblockSection>
            <apex:pageblockSection rendered="{!Case.Status = 'Escalated' && isSuccessFullySaved}"> 
                     <apex:inputField value="{!Case.Fieldyouwanttoshow}"/> 
                     <apex:inputField value="{!Case.Fieldyouwanttoshow}"/> 
</apex:pageblockSection>
            <apex:pageblockSection rendered="{!Case.Status = 'Working' && rend1}">
                <apex:outputField value="{!Case.Working_1__c}"/>
                <apex:outputField value="{!Case.Working_2__c}"/>
            </apex:pageblockSection>
            
            <apex:pageblockbuttons>
                 <apex:commandButton value="Save" action="{!save}" rerender="theForm" rendered="{!not(isSuccessfullySaved)}"/>
                 
            </apex:pageblockbuttons>
            
        </apex:pageblock>
    </apex:form>
</apex:page>

 
sfdc@isha.ax1814sfdc@isha.ax1814
Hi Dushyant,

Thabk you somuch for yur reply. Iam new to this so asking help for small changes as well.

I have modified my vf page like below.
 this is a inline vfpage on case . when ever page loads still fields are in edit mode[inpiut field ] find below screenshot for reference.


<apex:page standardController="Case" extensions="caseextension">
    
    <apex:form id="theForm">
        
        <apex:pageBlock mode="inlineEdit">
            <apex:pageblockSection >
                <apex:inputField value="{!Case.Status}">
                    <apex:actionSupport event="onchange" reRender="theForm"/>
                </apex:inputField>
            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageblock>
       
            <apex:pageblockSection rendered="{!Case.Status = 'Working' && not(isSuccessFullySaved)}">
                <apex:inputField value="{!Case.Working_1__c}"/>
                <apex:inputField value="{!Case.Working_2__c}"/>
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Case.Status = 'Escalated' && not(isSuccessFullySaved)}">
                <apex:inputField value="{!Case.NewText1__c}"/>
                <apex:inputField value="{!Case.New_Text2__c}"/>
           
            </apex:pageblockSection>
            
           
             <apex:pageblockSection rendered="{!Case.Status = 'Escalated' && isSuccessFullySaved}">
                <apex:outputField value="{!Case.NewText1__c}"/>
                <apex:outputField value="{!Case.New_Text2__c}"/>
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Case.Status = 'Working' && isSuccessFullySaved}">
                <apex:outputField value="{!Case.Working_1__c}"/>
                <apex:outputField value="{!Case.Working_2__c}"/>
            </apex:pageblockSection>
            <apex:pageblockbuttons >
                 <apex:commandButton value="Save" action="{!save}" rerender="theForm" rendered="{!not(isSuccessfullySaved)}"/>
            </apex:pageblockbuttons>
            
        </apex:pageblock>
    </apex:form>
</apex:page>


User-added image


Regards,
Isha