You need to sign in to do that
Don't have an account?
Issue with JavaScript button: value is undefined
Hi community,
I have a JavaScript button that calls successfully an Apex class.
However, now I want to give the Opportunity record as a parameter to my Apex method but it does not work.
(it is a detail page button)
When clicking on the button from the Opportunity, the message I get is:
"
A problem with the OnClick JavaScript for this button or link was encountered:
value is undefined
"
This is my JS button:
{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")} var opp = sforce.SObject("Opportunity"); var myString = sforce.apex.execute("ClosedDuplicate","myMethod2",{contextOpp:opp}); window.alert(myString);
Basically, what I am unable to do is transmit the opportunity record from where the button has been clicked to my Apex method. I hope its is possible. If not can someone give me the script for trasnmitting the record ID?
Thanks!
After further diggin, I found a solution thanks to this blog:
http://hometeamconsulting.com/update-records-javascript-buttons/
Instead of
I put:
That worked....
All Answers
Hi ,
For passing the parameter in such cases to controller, you must use apex:param visualforce component.
See the example below,
http://boards.developerforce.com/t5/Visualforce-Development/Passing-record-Id-from-a-related-list-to-a-method-associated/td-p/592431
Regards,
Ashish
Thank you, but I am asking for a solution via JavaScript, not Visualforce
After further diggin, I found a solution thanks to this blog:
http://hometeamconsulting.com/update-records-javascript-buttons/
Instead of
I put:
That worked....
Thats is great! Thank you for posting here.
Regards,
Ashish