Friday, February 28, 2014

Some times in salesforce we need to call apex method from java script button. we need to use following code for this.

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

var sObjRecId = "{!Quote__c.Id}"; 
/*
   Parameters :
   parameter1 = class name
   parameter 2 = method which we are calling.
   parameter 3 = parameters for method, separated by comma.
                          Note : if no parameter than need to put empty braces. liek {}
*/
sforce.apex.execute("CloneWithChilds", "cloneRecords",{sObjId : sObjRecId });