This question already has an answer here:

I have a public emailing apex class I need to call that from onclick javascript button of a detail page. Can someone let me know , if I can do that? Please give me an example. I am not getting it.

I have a global webservice method that receives List of an Sobject record.

Apex webservice method

webservice static void sendMails(List<Form_Requests_abv__c> newrequests)
        Set<Id> formIds = new Set<Id>();
        for (Form_Requests_abv__c  fr : newrequests) 

        List<String> sendtoemail = new List<String>();        

        List<ABV_Form_Request_abv__c>  Useremails= ABV_Form_Request_abv__c.getAll().values();
           for(ABV_Form_Request_abv__c Useremail : Useremails)

How can I pass value there?

My javascript code

var leadIds = {!GETRECORDIDS($ObjectType.Form_Requests_abv__c)}; 
sforce.apex.execute("MailerUtils","sendMails",{newrequests: leadIds});

marked as duplicate by Adrian Larson, dphil, Himanshu, Boris Bachovski, Vamsi Krishna Feb 24 '16 at 0:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Does that detail page have a controller, or is it a standard view? Because you can call public methods on a controller in javascript with <apex:actionFunction> – mkorman Feb 23 '16 at 17:51

The input to the webservice is passed as a serialized JSON string.

You need to accept a string as input to the webservice method and deserialize it in the method.

So the definition of the webservice would be:

webservice static void sendMails(String newrequests){

To get the list, you would do this:

List<Form_Requests_abv__c> = (List<Form_Requests_abv__c>)JSON.deserialize(newrequests,List<Form_Requests_abv__c>.class);

The rest of your method can then be used as-is.

  • It gives this error - unexpected token: 'List' – Testing_SFDC Feb 24 '16 at 13:57
  • I am putting the code like this. webservice static void sendMails(String newrequests) { List<Form_Requests_abv__c> = (List<Form_Requests_abv__c>)JSON.deserialize(newrequests,List<Form_Requests_abv__c>.class); //List<Form_Requests_abv__c> newrequests Set<Id> formIds = new Set<Id>(); for (Form_Requests_abv__c fr : newrequests) { formIds.add(fr.id); – Testing_SFDC Feb 24 '16 at 13:58
  • I have implemented your changes but it shows - No operation found for the class. Please check WSDL. – Testing_SFDC Feb 24 '16 at 14:15

As outlined here, your class and methods should be global and webservice.

  • Please find my question updated. If not using Public class I have a global class but need to pass List of the particular Sobject – Testing_SFDC Feb 23 '16 at 18:11
  • Please see my code snippets. – Testing_SFDC Feb 23 '16 at 18:15
  • Have you tried Id/Set<Id>/List<Id>? – Adrian Larson Feb 23 '16 at 18:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.