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
Vimal Bhavsar 6Vimal Bhavsar 6 

How to Call Webserivce on Custom button on Account Page

Hi,

I want to add one custom button on Account Create page and on that button i want to call one webservice by which i can add that account information data  in to external database/SQL database.

please advice for the same thnx
Virendra ChouhanVirendra Chouhan
Hi Vimal,

You have to add a Custom button with Java Script .
and use this code

sforce.apex.execute("ClassName", "Webservice_MethodName" ,{Parameter});
in this method First parameter is the Name of class which have Webservice method
And second one is the Name of webservice Method
and if this method have some parameter then write on the last one .

Cheers
sunny522sunny522
Hi vimal,
              First create a webservice apex class as global as shown below
global class MyClass2 {
  webservice static String processDetails(String accID){

     return 'test';
  }
}

now create a button as you like with behaviour as "Execute javascript" and content source with "on click javascript".
then write your javascript code as shown below

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
try{
var accId='{!Account.Id}'
var result = sforce.apex.execute("MyClass2", "processDetails",{accId : accId});

}
catch(err) {

alert(err);
}

sforce.apex.execute() method is used to call webservice methods.

let us know if it helped