+ Start a Discussion
pooja biswaspooja biswas 

difference between actionfunction and @remoteaction with example

Hello
I am looking for a scenario where I need to use @RemoteAction for an visualforce page.
Also please let me know exact differences between the two.

Thanks
Pooja 
 
sukanya banekarsukanya banekar
Hi Pooja,

For difference refer to https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_compare_actionfunction.htm

Scenario where you can use remoteAction for example: 
If you are creating drag and drop component (drag one row from one table to another table and at the backend update some id's) then use remote action. If you are playing with dom elements and you want to call controller's method use remote action.

I hope this helps you to usnderstand.

Thanks,
Sukanya 
pooja biswaspooja biswas
Hi
I have 2 apex classes , class A & class B
In both classes I have 2 methods with @remoteAction.

I create visualforce page for classB , write a javascript to call method fo classB
Is it possible to call method of classA in the <apexPage:controller="classB"> ?

Pooja
Archit Sharma 13Archit Sharma 13
Hello Pooja,

According to my understanding the main difference is that in Action Function we cannot return value to the Visualforce page i.e callback.
Remote Function or JavaScript remoting: It  provides support for Apex methods used in Visualforce to be called via JavaScript. We can return value to the the Visualforce page.
 
sukanya banekarsukanya banekar
Hi Pooja,

Yes you can call class A method but not in javascript. You can call class B's method in javascript and then in class B's method call class A's method.

I hope this helps you.

Thanks,
Sukanya Banekar