4

I have a javascript button on my product layout named "ListToEbay" and I have written a controller to invoke the EndItem() service method of ebay api.

Below is the method:--

public void  removeItemFromEbayList() {
  HttpRequest req = new HttpRequest();
  Http http = new Http();
  sEnvelopHandlerForEndingList='Request XML';
  req.setBody(sEnvelopHandlerForEndingList);
}

I want to execute this method directly on clicking that button, without going or opening a VisualForce Page. How can I accomplish that?

screenshot

2 Answers 2

5

You have to make use of AJAX toolkit to call the method in Apex Controller.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
//sforce.apex.execute("classname","methodname","parameters seperated by comma");
sforce.apex.execute("classname","removeItemFromEbayList");

The consideration for this is that the class and the methods should be global and webservice. so you should modify the access modifier in your class to global and method from public to webservice.

5
  • Thanks for reply.i am implementing it now and will come down with the result. Commented Sep 4, 2015 at 10:20
  • 1
    Updated the access modifiers for the class and method. Commented Sep 4, 2015 at 11:21
  • @VigneshwaranG Do these apex method invocations from javaacript also counted as callout?
    – javanoob
    Commented Sep 4, 2015 at 12:00
  • 2
    @javanoob Yes. It is counted as callout. Commented Sep 4, 2015 at 12:05
  • @crmevengelist How is the implementation result coming up. Any positive outcome? Commented Sep 7, 2015 at 8:40
2

If im not mistaken, the function should be define as webservice (global is not enough for the method), as follows :

    webservice void  removeItemFromEbayList(){...}

And note that it will count against an API call.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .