Invoke Webservice/Apex Class using Custom Button

Apex Sep 24, 2014

Best Suitable case: Invoking WebService using Custom button from Record detail page

1 . Create a global Apex Class as shown,

global class wsAccountUpdate {    
    webService static void updateAccount(Id accId) { 
        Account a = [SELECT Id, Name, OwnerID 
                     FROM Account
                     WHERE Id =: accId];
        // above is sample query you can replace with your own             
        .....logic goes here
        update a;            

2 . Create a Custom button

A glance of Custom Button creation,

here how we invoke Apex Class,


{accId: "{!Account.Id}"});;

Passing Parameters, right now we're passing only one parameter, if you want to do pass more parameters those should be coma seperated as shown,


{param1: "value1"
,* param2: "value2", param3: "value3"});

NOTE: Most importantly dont forget to add custom button in Page Layout

Phanindra Mangipudi

Salesforce, Lightning Web Componets, Node.Js, Angular 2+, Bootstrap