5

Is there any way we can add Execute Javascript custom page button to Visualforce page and reuse it. I am just checking if any way we can save writing JS code is button again in VF page.

MY Visualforce page in Question is StandardController Page.

enter image description here

  • Do you want to have a VF page redirect from the Some JS code Goes here section?please clarify – Rao Jun 27 '13 at 23:54
  • Nope its not JS redirection. it executes JS code – Prafulla Patil Jun 28 '13 at 0:02
  • Just a thought you question is probably better titled, "How to share JavaScript between Custom Buttons and Visualforce pages?" – Andrew Fawcett Jun 28 '13 at 0:32
  • updated question – Prafulla Patil Jun 28 '13 at 2:15
5

You should be able to store your JavaScript as JS file in a Static Resource. Then use REQUIRESCRIPT (see trick and caviets here) in the Custom Button script and INCLUDESCRIPT in the Visualforce page. This should allow you to share your JavaScript.

Alternatively, depending on your skills and use case, you could also consider writing some shared Apex code either as a shared function between two controllers or a single controller used by both the Custom Button VF page and the other VF page/s in your solution.

3

There's an idea: Allow references to Static Resources on Custom Buttons with OnClick JavaScript. In it there's a link to this blog post Using static resources with Salesforce custom Javascript buttons that outlines a hack that would allow you to have a single source of the JavaScript reside in a static resource and refer to it from the custom button using the REQUIRESCRIPT function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.