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
krishna casukhela 7krishna casukhela 7 

call apex class from javascript

Hello friends
I am just famliarisng myself with Javascript.
Can any one pls let  me know in what real time scenario do we need to call a apex class / method using javascript with an specific example​​?

If SOQL query in apex method return 50K records is it a good practice to call apex method from javascript:?


thanks
krishna​
IshwarIshwar
Amit Chaudhary 8Amit Chaudhary 8
For this you can try below two option
Option 1:- JavaScript Remoting
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

Option 2:- Web Service Method
http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

if({!AAA__c.Name}!=Null)
{
    sforce.apex.execute("MyClass","myMethod",{}"});
    alert("This is {!AAA__c.Name}");
}
 
global class MyClass
{
    webservice static void myMethod() // you can pass parameters
    { 
         // Do something
    }
}

Please let us know if this will help you

Thanks
Amit Chaudhry

 
krishna casukhela 7krishna casukhela 7
Hi amit
a)from project ​perspective which is a better option  javascript remoting or using webservice.
b) if I am implementing webservice method is there any chance that governor limits will be effect ?

pls clarify
thanks
krishna​​​
Amit Chaudhary 8Amit Chaudhary 8
Both option are good.
a)from project ​perspective which is a better option  javascript remoting or using webservice.
Amit :- Try Option 2:- Web Service Method

b) if I am implementing webservice method is there any chance that governor limits will be effect ?
Amit:- No.