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
Renu anamalla 17Renu anamalla 17 

Hi, When do we go for CommandButton and when do we go for Action function ?please explain Difference also..

Hi, When do we go for CommandButton and  when do we go for Action function ?please explain Difference also..
atul patil 7atul patil 7
Hello Renu,

-you can use command button when you want to call controller method directly on click of button
<apex:commandButton action="{!save}" value="Save" id="theButton"/>

-you can call action function from javascript method or oncomplete or onclick of any event in this case controller method not directly called
1. herte action function call from javascript method
<script>
       function demoCall(){
        sayHello();
​          }
</script>
<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>

2.Here action function called oncomplete of action
<apex:commandButton action="{!save}" value="Save" id="theButton" oncomplete="sayHello();"/>

​<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>

3. you can call action function on acomplete of another action function 
<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus" oncomplete="myFunction();"/>

<apex:actionFunction name="myFunction" action="{!sayHi}" rerender="out" status="myStatus" />

i hope this is helpful for you
thanx,
Atul Patil
salesforce developer 
Mustafa JhabuawalaMustafa Jhabuawala
There's no difference in the Apex side by using action function and command button.

Difference is in the markup.

A command button allows to call an apex method when the button is pressed, but under no other circumstances.

A action function allows to execute an apex method method via JavaScript which can be used in a number of different scenarios.

So if you want to call an apex method without performing any operations on client side then you can use command button.

If you want to perform some operations once you click on a button after that you want to call apex method then in that case you should go with action function.