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
DmonikaDmonika 

i have a form with save button and view records buttons. Now, while clicking on view records button the required fields should avoid.

Here is my code.

VFPage:-
<apex:page Standardcontroller="Doctor__c" extensions="DoctorView" >
<apex:form >
<apex:pageMessages />
<apex:tabPanel switchType="Client" >
<apex:tab label="Doctor" >
       <apex:pageBlock >
     
       <apex:pageBlockSection columns="2">
      <apex:inputField value="{!Doctor__c.Name__c}"/>
      <apex:inputField value="{!Doctor__c.DOB__c}"/>
      <apex:inputField value="{!Doctor__c.ContactNumber__c}"/>
      <apex:inputField value="{!Doctor__c.Department__c}"/>
       </apex:pageBlockSection>

      <apex:pageblockbuttons location="bottom">
        <apex:commandButton value="Save" action="{!doctorRecord}" />
 
       </apex:pageblockbuttons>
       </apex:pageBlock> 
      
       <apex:pageBlock >
        
        <apex:pageBlockButtons location="bottom">
         <apex:commandButton value="ViewDetails" action="{!viewRecords}" />
        </apex:pageBlockButtons>
       
            <apex:pageBlockTable value="{!doctorList}" var="dL">
                <apex:column headerValue="Name" value="{!dL.Name__c}"/>
                <apex:column headerValue="Phone" value="{!dL.ContactNumber__c}"/>
                <apex:column headerValue="DOB" value="{!dL.DOB__c}"/>
                <apex:column headerValue="Department" value="{!dL.Department__c}"/>
            </apex:pageBlockTable>
           
       </apex:pageBlock>
 </apex:tab>    
  </apex:tabPanel>
       </apex:form>
</apex:page>

Apexclass:-
public class DoctorView {
    
    public Doctor__c doctor = new Doctor__c();
    public List<Doctor__c> doctorList{get;set;}
    
    public DoctorView(ApexPages.StandardController controller) {
    
        this.doctor = (Doctor__c)controller.getRecord();

    }
    
    public pageReference doctorRecord()
    {
        insert doctor;
       
        return null;
    }
    
    public pageReference viewRecords()
    {
         doctorList = new List<Doctor__c>();
        doctorList = [Select Id,Name__c,ContactNumber__c,DOB__c,Department__c from Doctor__c];
        return null;
    }

}
Best Answer chosen by Dmonika
Shashikant SharmaShashikant Sharma
You have two options here:

Use: Immediate="true" in your command button.

<apex:commandButton immediate="true" value="ViewDetails" action="{!viewRecords}" />

Or you could use onclick event of button and call a java scrpt method to naigate.




 

All Answers

Shashikant SharmaShashikant Sharma
You have two options here:

Use: Immediate="true" in your command button.

<apex:commandButton immediate="true" value="ViewDetails" action="{!viewRecords}" />

Or you could use onclick event of button and call a java scrpt method to naigate.




 
This was selected as the best answer
DmonikaDmonika
@Shashikant Sharma Thank you it works with immediate="true"