Hot Posts

Can you explain the various types of actions in Salesforce?

Can you explain the various types of actions in Salesforce?

Action Function:Utilize AJAX to invoke the controller method from JavaScript, allowing for the execution of the action function from various locations on the Visualforce page. It must be child of apex:form.

<apex:actionFunction name="sendEmail" action="{!sendEmailFunction}"></apex:actionFunction> 

actionFunction : provides support for invoking controller action methods directly from JavaScript code using an AJAXrequest

Example :
actionFunction : provides support for invoking controller action methods directly from JavaScript code using an AJAXrequest

Example :
<!-- Page: -->
<apex:page controller="exampleCon">
<apex:form>
<!-- Define the JavaScript function sayHello-->
<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out"
status="myStatus"/>
</apex:form>
<apex:outputPanel id="out">
<apex:outputText value="Hello "/>
<apex:actionStatus startText="requesting..." id="myStatus">
<apex:facet name="stop">{!username}</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<!-- Call the sayHello JavaScript function using a script element-->
<script>window.setTimeout(sayHello,2000)</script>
<p><apex:outputText value="Clicked? {!state}" id="showstate" /></p>
<!-- Add the onclick event listener to a panel. When clicked, the panel triggers
the methodOneInJavascript actionFunction with a param -->
<apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn">
Click Me
</apex:outputPanel>
<apex:form>
<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript"
rerender="showstate">
<apex:param name="firstParam" assignTo="{!state}" value="" />
</apex:actionFunction>
</apex:form>
</apex:page>

/*** Controller ***/
public class exampleCon {
String uname;
public String getUsername() {
return uname;
}
public PageReference sayHello() {
uname = UserInfo.getName();
return null;
}
public void setState(String n) {
state = n;
}
public String getState() {
return state;
}
public PageReference methodOne() {
return null;
}
private String state = 'no';
}

Action Support: Invoke the controller method using AJAX when an event occurs on a page, like onMouseOver, onClick, etc., and we can use action support for a particular single apex component.A component that adds AJAX support to another component, allowing the component to be refreshed asynchronously by theserver when a particular event occurs, such as a button click or mouseover.Used when we want to perform an action on a perticular eventof any control like onchange of any text box or picklist.

			<apex:outputpanel id="counter">
				<apex:outputText value="Click Me!: {!count}"/>
				<apex:actionSupport event="onclick" action="{!incrementCounter}" rerender="counter" status="counterStatus"/>
			</apex:outputpanel>

  

Example :

  <!-- Page: -->
<apex:page controller="exampleCon">
<apex:form>
<apex:outputpanel id="counter">
<apex:outputText value="Click Me!: {!count}"/>
<apex:actionSupport event="onclick"
action="{!incrementCounter}"
rerender="counter" status="counterStatus"/>
</apex:outputpanel>
<apex:actionStatus id="counterStatus"
startText=" (incrementing...)"
stopText=" (done)"/>
</apex:form>
</apex:page>


/*** Controller: ***/
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}

  

ActionPoller: A timer that sends an AJAX update request to the server according to a time interval that you specify. Update requests can then result in a full or partial page update. You should avoid using this component with enhanced lists. ActionPoller is a timer component that has the capability to send AJAX requests at a pre-defined interval. The minimum interval is set at 5 seconds, while the default interval is 60 seconds. The code snippet demonstrates the usage of this component with an interval of 50 seconds.

<apex:actionPoller action="{!incrementCounter}" rerender="counter" status="counterStatus" interval="50" /> 
 

A timer that sends an AJAX update request to the server according to a time interval that you specify. The update request canthen result in a full or partial page update. You should avoid using this component with enhanced lists.Used when we want to perform an action on server again and again for a particular time interval.

Example :

  <!-- Page -->
<apex:page controller="exampleCon">
<apex:form>
<apex:outputText value="Watch this counter: {!count}" id="counter"/>
<apex:actionPoller action="{!incrementCounter}" rerender="counter" interval="15"/>
</apex:form>
</apex:page>
/*** Controller: ***/
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
  

actionRegion: An area of a Visualforce page that demarcates which components should be processed by the Overview server when an ajax request is generated.

actionStatus: A component that displays the status of an AJAX update request. An AJAX request can either be in progress or complete.

Post a Comment

0 Comments