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
Saravanan @CreationSaravanan @Creation 

How to write test code for javascript remoting method in apex class

Hi All,

 

can any one please tell me how to write test code for java script remoting method in Apex class.And I am passing argument from page.

 

sample codes are appriciated.

Best Answer chosen by Admin (Salesforce Developers) 
Saravanan @CreationSaravanan @Creation

yes just like below

 

       String s='Base Product';
       Class_Name.RemoteMethodName(s);

 

   In the above code 's' is the parameter value that i need to pass to remote method.

All Answers

Starz26Starz26

Just like any other class. The remoting just allows the JAVA to call it. It does not change (basically) how you initiate a test method for the class

mauricio.ramos@corpitalmauricio.ramos@corpital

Hello,

 

The previous reply is true but with a little twist given that you are testing goblal methods so the usual way of writting test methods for controllers is slightly different. 

 

Basically to test a Remoting method, just call the method directly like so:

 

String param = 'test';                // lets pretend this is the parameter you need to pass into the method. 

remotingMethod1(param);     //this is the remoting method your calling. 

 

 

If you return a value from the method then just create the proper variable and assign the results to it. Then do some asserts to verify its doing what it should.

 

 

BTW: YOU should be the one to mark as Solution the answers you feel were the ones that answered your issue, not us. So please check if this is solving your issue and mark it as solved so others can benefit from your experience. 

 

BlubBlub
Did you find a way how to write the test class?
Saravanan @CreationSaravanan @Creation

yes just like below

 

       String s='Base Product';
       Class_Name.RemoteMethodName(s);

 

   In the above code 's' is the parameter value that i need to pass to remote method.

This was selected as the best answer