Visualforce Immediate Attribute on CommandLinks and CommandButtons

Visualforce Immediate Attribute on CommandLinks and CommandButtons, immediate attribute salesforce, sfdc panda, sfdc attribute, immediate attribute example, visualforce example, sfdc panda, infallible techie, jitendrazaa, dineshkumar rajamani, salesforce example

Visualforce Immediate Attribute on CommandLinks and CommandButtons Technical Explanation :-

  • When we don’t want the validation rule to be fire during server request we set this attribute Immediate=”true”.
  • Default value of this immediate attribute is false.
  • When we are having functionality of Back to previous page or cancel button, where we don’t our validation rules to be fired. In this case if we didn’t set Immediate=”true” where validation rule will get fired and we end up in a state of unable to return to previous page.To avoid this case we need to set Immediate=”true” like below Visualforce Immediate Attribute on CommandLinks and CommandButtons example.
<apex:CommandLink action="{!cancelMethod}" value="Cancel Link" styleClass="btn" id="btnCancel" immediate="true">

<apex:commandButton value="Cancel" immediate="true" action="{!cancelbutton}"/>
  • We usually wire this attribute in cancel button to skip validation rules.

Apex class(Visualforce Immediate Attribute on CommandLinks and CommandButtons) :-

public class ImmediateVfcontroller{

public Boolean Flag1{get;set;}
 public Boolean Flag2{get;set;}
 public ImmediateVfcontroller(ApexPages.StandardController controller) {
 Flag1= false;
 Flag2= false;
 }

public pagereference savebutton(){
 Flag1= true;
 Flag2= false;
 return null; }

public pagereference cancelbutton(){
 Flag1= false;
 Flag2= true;
 return null; }

}

VF page(Visualforce Immediate Attribute on CommandLinks and CommandButtons) :-

<apex:page standardController="Account" extensions="ImmediateVfcontroller" >

<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons location="both">
 <apex:commandButton value="Save" action="{!savebutton}"/>
 <apex:commandButton value="Cancel" immediate="true" action="{!cancelbutton}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockSection >
 <apex:inputField value="{!account.name}"/>
 <apex:inputfield value="{!account.Type}" required="true"/>
 </apex:pageBlockSection>
 <apex:outputText value="Account Added succesfully" rendered="{!flag1}"/>
 <apex:outputText value="Account failed to be Added" rendered="{!flag2}"/>
 </apex:pageBlock>
 </apex:form>

</apex:page>


Be the first to comment

Leave a Reply

Your email address will not be published.


*