How to return value from Apex method to Javascript in Salesforce using a custom button?

Example:

Apex Class:

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


Custom Button Javascript:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

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

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


Output:


No comments:

Post a Comment