How invoke APEX method from custom button

Published on Author Code Father

Add following java script codes to, custom button’s javaScript ‘onClick’ section.

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

//Get Opportunity id 
var opId= "{!Opportunity.Id}";

//Call insertJob method by passing that Opportunity id 
sforce.apex.execute("JobService","insertJob",{op_id:opId});

//Redirect to that tab 
window.location = 'https://ap1.salesforce.com/a0G/o';

Note:

  • Thank you very much for Adam & Jeremy Ross for their guide, those are very much helpful to me.
  • Please add some comment if any one know, how can I retrieve Opportunity’ object rather than retrieve ‘Opportunity.Id’, thanks.

Comments

comments