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
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
 
 
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} 
try{ 
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"; 
alert(txt); 
}

Please let us know if it helps.

Best Regards,
Nagendra.P