Call Apex Class from Custom Button (JAVASCRIPT) in Salesforce



Step 1  :  Lets first create the Apex class

Things to Remember: 
  • Class needs to be a Global class 
  • and the method you intend to call from the javascript must be a WebService Method
e.g.

Global Class RG_LeadConversionCls {    

webservice static void LeadConvert(Id Leadid)
{       

}


Step 2 : Now to setup the custom Button.

  • Goto --> Setup --> Object --> Buttons, links and Actions section
  • Click New Button or Link
  • Enter the Name of the button
  • Behaviour : Execute Javascript
  • Content source : On-Click Javascript


{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

sforce.apex.execute("RG_LeadConversionCls","LeadConvertId",{Leadid:"{!Lead.Id}"});


Related Posts:

  • Parent to Child SOQL Account to Contact -Parent to Child SOQL Select id, Name,(Select Name,Birthdate,Email from Contacts) from Account where id=… Read More
  • Security in salesforce     1.  Internal Security – Profile Permission set OWD  (Organization wide default) User Role Sharing Rule 2. &nb… Read More
  • Licence in salesforce A user license determines the baseline of features that the user can access. Every user must have exactly one user license. Salesforce offers these… Read More
  • Profile in salesforce ·   Profiles define how users access objects and data, and what they can do within the application. When you create users, you assign a … Read More
  • LeadConvert The convertLead Database method converts a lead into an account and contact, as well as (optionally) an opportunity. TheconvertLead t… Read More

0 comments:

Post a Comment