Here is the simple example to execute apex method and
passing parameters from a custom button in salesforce.
Here is the simple example to execute apex method and
passing parameters from a custom button in salesforce.
Apex Class:
- global class NameMergeController{
- webService static string getName(String fName, String lName){
- String fullName = 'Hi '+ fName +' '+ lName;
- return fullName;
- }
- }
Button Code:
Passing Static Parameters:
- {!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
- {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
- var res = sforce.apex.execute("NameMergeController","getName",{fName :"Salesforce", lName: "Kings"});
- alert(res);
Passing Dynamic Parameters:
- {!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
- {!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
- var res = sforce.apex.execute("NameMergeController","getName",{fName:"{!Account.Name}", lName:"{!Account.Name}"});
- alert(res);
Where,
NameMergeController > Class name
getName > Method name.
Please check this link, if you receive "No service available for class" exception.