+ Start a Discussion
Aditya Singh 37Aditya Singh 37 

Calling @FutureCallout Apex Class Via custom button on Leads

I created a custom Java Script button on Lead Object. Should I call a @InvocableMethod Apex class or a futurecallout apex class and pass the Lead ID to the class to further process ?
i am calling futurecall out class with invokeable method using that in a Flow and its working perfectly. Just want to use a custom button too.
This is the code:
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/35.0/apex.js")} var result = sforce.apex.execute("Futurecallout","ApexWSclass", {Id:'{!Lead.Id}'}, {Email:'{!Lead.Email}'}, {Firstname:'{!Lead.FirstName}'}, ); alert(result); window.location.reload();
NagendraNagendra (Salesforce Developers) 
Hi Aditya,

If you want to take the javascript invocation route, then it should have to be a web service method.
The other way to do it is via a VF Page and Custom Controller.

Please find the sample code below for your reference:
global class MyClass {
  webservice static String processDetails(String accID){
     return 'test';
The custom button has been created as a Detail Page Button executign Javascript.
The Javascript is as follows
var accId='{!Account.Id}'
var result = sforce.apex.execute("MyClass", "processDetails",{accId : accId}); 
var url = 'http://www.google.com'
window.open( url); 
catch(err) { 
txt="There was an error on this page.\n\n"; 
txt+="Error description: " + err.description + "\n\n"; 
txt+="Click OK to continue.\n\n"; 

Please let us know if it helps.

Best Regards,