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
Abdulla d 5Abdulla d 5 

list view button to invoke webservice call?

I have requirement to create a list view button on Accountcert object. That button just need to call the webservice  method. this is my requirement. 
that method need to pass parameters. how could i achieve this? this need to support in lightning as well
Raj VakatiRaj Vakati
Yes .. you can do it like below if you are in class 

 
global without sharing class MyWebservice {

    WebService static String myFunction(String param) {

        if (String.isNotBlank(param) {

            try {
                // Some logic here

                return 'OK';    
            }
            catch (Exception e) {
                return 'ERROR';
            }
        }
        else {
            return 'ERROR';
        }
    }
}
 
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")} 

var callout = "" + sforce.apex.execute(
    NamespacePrefix + "MyWebservice",
    "myFunction",
    {param:"{!MyObject__c.Id}"}); 

if (callout == 'OK') { 
    alert("Webservice call was ok."); 
    window.location.reload(); 
} 
else { 
    alert("Webservice call failed!"); 
}


Or you can do it using Visualforce controller or lightning component also 


http://www.infallibletechie.com/2012/10/calling-apex-method-from-custom-buttom.html
http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html
https://andyinthecloud.com/2013/07/16/how-to-call-apex-code-from-a-custom-button/
https://www.greytrix.com/blogs/salesforce/2014/09/24/consuming-external-web-service-in-apex/
https://www.greytrix.com/blogs/salesforce/2014/09/24/create-button-for-list-view/
http://sfdcsrini.blogspot.com/2014/11/custom-salesforce-button-to-execute.html


http://sfdcmonkey.com/2017/04/16/add-lightning-component-lightning-action/
Abdulla d 5Abdulla d 5
Already webservice method is exist bro, that i need to call when i click on this button. how we can pass the current select record ids to that button. i didn't get
Daniel Zeidler (DZ)Daniel Zeidler (DZ)
One way is to set up a custom list button and set its content source to a visualforce page.

Here is an example of how that is done: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_custom_button.htm

You can have the Visualforce page's controller extension to call the webservice upon page load. The selected record id's can be obtained by the StandardSetController passed in to the extensions constructor.

 
Abdulla d 5Abdulla d 5
It's list view button bro, not list button controller
Abdulla d 5Abdulla d 5
How to pass the binding variable to query in javascript? this is where i'm failing
var myquery = "SELECT id from CertTask__c Where Cern__c="+selectedLeads[0] ;
Daniel Zeidler (DZ)Daniel Zeidler (DZ)
You can't use a javascript list view buttons in Lightning experience.

What you can do in tie a list view button to a visualforce page with a list view controller. When the list view button is pressed, the selected records are passed to the visualforce page as parameters. The visualforce list view controller extension can be used to retrieve those selected records and make the callout.