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
mani kadimi 13mani kadimi 13 

Hi, I have one vf page in that perform two actions like save and saveandnext in one action some fields are required but another action that fields are not required..How can achieve this functionality?/

Madhukar_HeptarcMadhukar_Heptarc
Hi Mani,

I have understand your requirement.
My suggestion is to create 2 Visual force pages and One controller is required.
In my below example shows to write 2 different actions.
 
Home Page .Vf:
============
<apex:page >
    <center> 
        <font size="6" color="BLUE"> <b> Application</b> </font>
    </center> 
    
    <apex:form >
        <apex:pageBlock title="NEW ENTRIES">
            <center>
                <apex:commandButton value="Save" action="https://c.ap2.visual.force.com/apex/Community_Action1"/>
                <apex:commandButton value="Save and Next" action="https://c.ap2.visual.force.com/apex/Community_Action2"/>
            </center>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Patient Controller.apx :
=================
public class patientcontroller {
public Patient__c p {get; set;}

public patientcontroller(){
p = new Patient__c();
}

public PageReference save() {
insert p;    
pagereference pageref =new PageReference('/apex/HomePageVF');
return pageref;
}

public PageReference saveandnew() {
insert p;

PageReference PageRef = new PageReference('/apex/PatientVFPage');
p.clear();
return PageRef;
}
}

Community_Action1 .VF
==================
<apex:page sidebar="false" showHeader="false" controller="patientcontroller">
    <apex:form >
        <apex:pageBlock title="Action 1">
            <apex:pageBlock >
                <apex:pageBlockSection >
                    <apex:inputField value="{!p.Name}" required="true"/>
                    <apex:inputField value="{!p.Address__c }"/>
                    <apex:inputField value="{!p.Age__c }" required="True"/>
                    <apex:inputField value="{!p.Email__c}"/>
                    <apex:inputField value="{!p.Mobile__c}" required="True"/>
                </apex:pageBlockSection>
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="SaveAndNext" action="{!saveandnew}" />
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Community_Action2.VF:

==================

<apex:page sidebar="false" showHeader="false" controller="patientcontroller">
    <apex:form >
        <apex:pageBlock title="Action 2">
            <apex:pageBlock >
                <apex:pageBlockSection >
                    <apex:inputField value="{!p.Name}" required="true"/>
                    <apex:inputField value="{!p.Address__c }"/>
                    <apex:inputField value="{!p.Age__c }"/>
                    <apex:inputField value="{!p.Email__c}"/>
                    <apex:inputField value="{!p.Mobile__c}"/>
                </apex:pageBlockSection>
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="SaveAndNext" action="{!saveandnew}" />
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>


You can access Different type of fields from Visual force pages by using below action 
<apex:commandButton value="Save" action="https://c.ap2.visual.force.com/apex/Community_Action1"/>
<apex:commandButton value="Save and Next" action="https://c.ap2.visual.force.com/apex/Community_Action2"/>


Please let me know if it helps you/ Any help required.

Thanks & Regards 
Madhukar_Heptarc