You need to sign in to do that
Don't have an account?
kjtseng
Javascript code in Custom Button
Hi,
I have two custom buttons: one in the list view and one in the detail page for a custom object. The onClick Javascript code for the list button was able to get all the record Ids. But the code for the detail page button was not able to get any id at all. Both buttons call the same Apex class. I followed the code sample from http://developer.force.com/cookbook/recipe/creating-a-button-with-apex.
I have two custom buttons: one in the list view and one in the detail page for a custom object. The onClick Javascript code for the list button was able to get all the record Ids. But the code for the detail page button was not able to get any id at all. Both buttons call the same Apex class. I followed the code sample from http://developer.force.com/cookbook/recipe/creating-a-button-with-apex.
onClick Javascript Code for the Custom List Button on the Listview: {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} var recordIdArray = {!GETRECORDIDS($ObjectType.Term_Sheet__c)}; console.log('the record Ids are' + recordIdArray); if (recordIdArray.length) { alert("Calculating..."); var retStr = sforce.apex.execute("LScurrMonthInterest", "calculateInterestToDate",{ts_idList: recordIdArray}); alert(result[0] + " Done!"); //response } else if (recordIdArray.length == 0) { alert("Please select the Term Sheet to which" + " you would like to calculate current month interest as of today."); } ~~~~~~~~~~~~ onClick Javascript Code for the Custom Detail Page Button on the Detail Page: {!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} var recordIdArray = {{!Term_Sheet__c.Id}}; console.log('the record Ids are' + recordIdArray); if (recordIdArray.length) { alert("Calculating..."); var retStr = sforce.apex.execute("LScurrMonthInterest", "calculateInterestToDate",{ts_idList: recordIdArray}); alert(result[0] + " Done!"); //response } else if (recordIdArray.length == 0) { alert("Please select the Term Sheet to which" + " you would like to calculate current month interest as of today."); } ~~~~~~~~~~~~~ Apex Class: global class LScurrMonthInterest{ WebService static void calculateInterestToDate(List<Id> ts_idList) { ....... } }
var recordIdArray = {{!Term_Sheet__c.Id}};
to
var recordIdArray = ["{!Opportunity.Id}"];
And finaly it looks like below. pls let me know is it working or not.
All Answers
var recordIdArray = {{!Term_Sheet__c.Id}};
to
var recordIdArray = ["{!Opportunity.Id}"];
And finaly it looks like below. pls let me know is it working or not.