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
ashish jadhav 9ashish jadhav 9 

what is the use of action region?

can you please tell me what is the use of action region? and why & when we're using it?
any sample example please.
Best Answer chosen by ashish jadhav 9
nagendra 6989nagendra 6989
HI ashish jadhav9,

This describes mainly about <apex:actionRegion> tag used in visualforce Page. <apex:actionRegion> is used to optimise VF performance.
ActionRegion tag defines which components  of VF page should be processed by Force.com server.
By Components  mean, all the visualforce tags like inputField, inputText, outputPanels etc.
See this simple example Below.

User-added image

User-added image
 
in above example if you enter account Name, then suddenly an error for Industry appears saying “You Must Enter a value”.
How come this error appeared ? even if we just entered “Account Name”?.
This is beacuse, when AJAX request is generated through event such as “onClick”, or “onChange” etc. , whole <apex:form> is submitted to theForce.com server to Process setting Industry value to NULL. Hence error appeared.

How to Solve this Issue?

User-added image

See this VF page code below.
we used <apex:actionRegion> tag for field “myAccount.Name”.
What it does?
“ActionRegion” tells Force.com Server which components should be proccessed. Here whatever inside an ActionRegion is processed by a server when AJAX request is generated on event such as “KeyPress” or “onClick” etc.
Thus we do not get an error.
Above code is tested in my developer org. So it should work even if you copied and pasted it as is.
Still if you have any queries please send me your email address for further communication.


Kindly mark it as solved if it really helps you.

Thanks & Regards,
Nagendra.P
9848950830

All Answers

nagendra 6989nagendra 6989
HI ashish jadhav9,

This describes mainly about <apex:actionRegion> tag used in visualforce Page. <apex:actionRegion> is used to optimise VF performance.
ActionRegion tag defines which components  of VF page should be processed by Force.com server.
By Components  mean, all the visualforce tags like inputField, inputText, outputPanels etc.
See this simple example Below.

User-added image

User-added image
 
in above example if you enter account Name, then suddenly an error for Industry appears saying “You Must Enter a value”.
How come this error appeared ? even if we just entered “Account Name”?.
This is beacuse, when AJAX request is generated through event such as “onClick”, or “onChange” etc. , whole <apex:form> is submitted to theForce.com server to Process setting Industry value to NULL. Hence error appeared.

How to Solve this Issue?

User-added image

See this VF page code below.
we used <apex:actionRegion> tag for field “myAccount.Name”.
What it does?
“ActionRegion” tells Force.com Server which components should be proccessed. Here whatever inside an ActionRegion is processed by a server when AJAX request is generated on event such as “KeyPress” or “onClick” etc.
Thus we do not get an error.
Above code is tested in my developer org. So it should work even if you copied and pasted it as is.
Still if you have any queries please send me your email address for further communication.


Kindly mark it as solved if it really helps you.

Thanks & Regards,
Nagendra.P
9848950830
This was selected as the best answer
DeepthiDeepthi (Salesforce Developers) 
Hi Ashish,

actionRegion provides an area of a Visualforce page that decides and separates which components should be processed by the force.com server when an AJAX request is generated. Only the components which are inside actionregion component are processed by server, so it increases visualforce page performance.
 
<!-- For this example to render properly, you must associate the Visualforce page 
with a valid opportunity record in the URL. 
For example, if 001D000000IRt53 is the opportunity ID, the resulting URL should be: 
https://Salesforce_instance/apex/myPage?id=001D000000IRt53
See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->

<apex:page standardController="Opportunity">
  <apex:form >
    <apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit">
   
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>               
      </apex:pageBlockButtons>

    <apex:pageBlockSection columns="1">
      <apex:inputField value="{!opportunity.name}"/>
      <apex:pageBlockSectionItem>
      <apex:outputLabel value="{!$ObjectType.opportunity.fields.stageName.label}" 
                        for="stage"/>
      <!-- 
           Without the actionregion, selecting a stage from the picklist would cause 
           a validation error if you hadn't already entered data in the required name 
           and close date fields.  It would also update the timestamp.
      -->
      <apex:actionRegion>
        <apex:inputField value="{!opportunity.stageName}" id="stage">
          <apex:actionSupport event="onchange" rerender="thePageBlock"
                              status="status"/>
          </apex:inputField>
          </apex:actionRegion>
      </apex:pageBlockSectionItem>
        <apex:inputfield value="{!opportunity.closedate}"/>
        {!text(now())}
        </apex:pageBlockSection>

      </apex:pageBlock>
    </apex:form>
</apex:page>


Please refer the below links for more examples on actionRegion:

http://sfdcsrini.blogspot.com/2014/07/visualforce-action-region-example.html 

http://www.sfdcpoint.com/salesforce/actionregion-visualforce-salesforce/ 

http://letusembed.com/2014/08/action-region-and-action-status-in-salesforce.html/ 

Hope this helps you!
Best Regards,
Deepthi
JyothsnaJyothsna (Salesforce Developers) 
Hi,

Action region is one of the most important tags which helps in increasing page performance. So we should try to make maximum use of action region in visual force page.
actionRegion component only defines which components the server processes during a request; it does not define which of the page are re-rendered when the request completes. We will still use reRender attribute on action component to decide area which should be rerendered AJAX request completes.

One more important point to note is that even when we use <apex:actionRegion> component, the whole form is still submitted, but the only area which is inside actionRegion is processed by the server.


One more important point to note is that by passing the validation rules using Action Region.


 I will explain the importance of actionRegion with the help of two examples. The first example will not use actionRegion and the second example will use actionRegion. Here in both example, we are trying to show phone textbox when we are selecting customer priority as high.

Example 1 :Without <apex:actionRegion>

User-added image

In this example, we are trying to show phone textbox when we are selecting high customer priority; then we are getting an error as SLA and Account name is required. So validation fails.

VisualForce Page:
<apex:page controller="withoutActionregionController" tabStyle="Account">
    <apex:form id="myform">
        <apex:pageBlock id="pageId">
            <apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false">
                 
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.Account.fields.CustomerPriority__c.label}" for="priority"/>
                     
                    <apex:inputField value="{!acc.CustomerPriority__c}" id="priority" >
                        <apex:actionSupport action="{!priorityChanged}" reRender="pageId" event="onchange"/>
                    </apex:inputField>
                </apex:pageBlockSectionItem>
                 
                <apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/>
            </apex:pageBlockSection>  
             
            <apex:pageBlockSection title="Other Account Details" columns="2" collapsible="false">
                <apex:inputField value="{!acc.SLA__c}" required="true"/>
                <apex:inputField value="{!acc.Rating}"/>
                <apex:inputField value="{!acc.name}"/>
            </apex:pageBlockSection>  
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
 
public class withoutActionregionController {
    public Account acc{get;set;}
    public Boolean showPhone{get;set;}
     
    public withoutActionregionController(){
        acc = new Account();
        showPhone = false;
    }
     
    public PageReference priorityChanged(){
        if(acc.CustomerPriority__c == 'High'){
            showPhone = true;
        }
        else{
            showPhone = false;
        }
        return null;
    }
}

Now in the second example, we will use the same code but with actionRegion tag. So in second example no validation error will be returned as only code inside action region component is processed by the server.

Example 2: with <apex:actionRegion>

User-added image
<apex:page controller="withActionregionController" tabStyle="Account">
    <apex:form id="myform">
        <apex:pageBlock id="pageId">
            <apex:pageBlockSection title="If you will select High Customer Priority then phone textbox will be shown" columns="1" id="out" collapsible="false">
                 
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.Account.fields.CustomerPriority__c.label}" for="priority"/>
                     
                    <apex:actionRegion >
                    <apex:inputField value="{!acc.CustomerPriority__c}" id="priority" >
                        <apex:actionSupport action="{!priorityChanged}" reRender="pageId" event="onchange"/>
                    </apex:inputField>
                    </apex:actionRegion>
                </apex:pageBlockSectionItem>
                 
                <apex:inputField value="{!acc.Phone}" rendered="{!showPhone}"/>
            </apex:pageBlockSection>  
             
            <apex:pageBlockSection title="Other Account Details" columns="2" collapsible="false">
                <apex:inputField value="{!acc.SLA__c}" required="true"/>
                <apex:inputField value="{!acc.Rating}"/>
                <apex:inputField value="{!acc.name}"/>
            </apex:pageBlockSection>  
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Code:
public class withActionregionController {
    public Account acc{get;set;}
    public Boolean showPhone{get;set;}
     
    public withActionregionController(){
        acc = new Account();
        showPhone = false;
    }
     
    public PageReference priorityChanged(){
        if(acc.CustomerPriority__c == 'High'){
            showPhone = true;
        }
        else{
            showPhone = false;
        }
        return null;
    }
}



Please check the below link for more examples of action region.

http://sfdcsrini.blogspot.com/2014/07/visualforce-action-region-example.html


​Hope this helps you!
Best Regards,
Jyothsna
ashish jadhav 9ashish jadhav 9
Thanks guys, but still I'm confused with it. When you say part within action region is processed by server, then what about other parts on VF page? They are not process by server? 
Alvin Bernard 1Alvin Bernard 1
Hi Jyothsna,

While executing above code without apex:actionregion, the phone input label does not appear when previewing the page without any record ID.
It does however work perfectly, when used with a record ID.

When used with apex:actionregion, it does work in both the scenario : when loaded with or without record ID.

Could you please advise the reason.