Return value from Apex method to Javascript in Salesforce using a custom button.For that i have controller :

global class web
    Webservice static String fetch(Id localId)
        return localId;

And Custom Button Javascript:


var r = confirm("Are you sure want to fetch?");

if(r == true)
    var a = sforce.apex.execute("web","fetch",{ID:"{!Account.Id}"});
    alert('Operation aborted');

When i clicked on custom Button one alert box appeared "Are you sure want to fetch?" that's ok after that second alert box give me the Error.Error is

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'soapenv:Client', faultstring:'No operation available for request {http://soap.sforce.com/schemas/package/web}fetch, please check the WSDL for the service.', }

So what can i do to solved the above problem...Please help me....

Snapshot of the Problem....



Do you have a namespace for your org you are working in? Say, if the namespace of the org is "abc", try the following code:

var a = sforce.apex.execute('abc.web', 'fetch', {localId:'{!Account.Id}'});

  • Thnaks Sir....this is very helpful...thanks again.... – Vivek113 Feb 21 '14 at 5:42

I think that you have to change the parameter name to localId.

Change this:

var a = sforce.apex.execute("web","fetch",{ID:"{!Account.Id}"});

by this:

var a = sforce.apex.execute("web","fetch",{localId:"{!Account.Id}"});
  • thanks for replay Sir,I just tried as a localId but the problem was not solved...please give me other solutions... – Vivek113 Feb 19 '14 at 8:01
  • try by changing the parameter type to string. This also, could generate a problem: fetch(Id localId) should be fetch(String localId) – Martin Borthiry Feb 19 '14 at 8:10
  • I tried Sir but not solved but here i think, the problem in WSDL for the service..I works on developer account so is it not a problem? – Vivek113 Feb 19 '14 at 8:17
  • 2
    Your class definition and javascript call are ok. The WSDL is not the problem, because you don't have to create it when you are referring sforce lib. I've created your same sample applied the mentioned fixes and it worked fine. – Martin Borthiry Feb 19 '14 at 8:23
  • Sir Here i add the snapshot of the alert box of the above defined problem...sir please help me to solve the problem... – Vivek113 Feb 19 '14 at 8:29

You have used String return type for your method and returning an Id.

Try this:

Webservice static Id fetch(Id localId)
        return localId;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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