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
占一 逯占一 逯 

Testing Method with @RemoteAction noted

I wanna test a method which has "@RemoteAction" noted in apex test class, but got  a failed message such as "web service callout not supported" in console, could anybody tell me why?
Best Answer chosen by 占一 逯
Shruti SShruti S
You cannot use "@RemoteAction" annotation in Test Classes. You should be writing API Mocks for testing the API Callouts in your Apex Class.
You can refer this link to know more about writing Unit Test Classes for API Callouts - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing.htm" target="_blank)

If you are still stuck, please let us know and we can help you further.

All Answers

Shruti SShruti S
You cannot use "@RemoteAction" annotation in Test Classes. You should be writing API Mocks for testing the API Callouts in your Apex Class.
You can refer this link to know more about writing Unit Test Classes for API Callouts - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing.htm" target="_blank)

If you are still stuck, please let us know and we can help you further.
This was selected as the best answer
占一 逯占一 逯
Thk you very much for your reply, it's really do work. But sometime I got error[System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out] when running test. It's not happend everytime, do you know this issue?
占一 逯占一 逯
I hava fixed the issue above, it's not about calling out. Nice day.