Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Use Case - There is Javascript execute button on Account page layout named 'Update Account' -


//JSsript code which updates account based on some logic 
//40 or 50 lines of Code

Problem with above button is it loads all this Javascript on every account pageview and kindof slows down each page view. what if we have 2 or more buttons then again its more time to load. Is there any way we can store Javascript in static resources and then load it only when user clicks button and then execute it ?

Note: I already know that you can Create Apex Webservice method and then call it from JS but wanted to check if there is any alternate way to do this.

share|improve this question

Each of your custom buttons could be written as so, letting 'RequireScript' determine whether your static resource script has already been loaded into the page (by another button).

If you can abstract the functions into a static resource file, the resource will only be loaded once and the button action can then call the function defined within the static resource.



//JSsript code which updates account based on some logic 

Here is a bit more info about the anti-caching number contained within the static resource URL path. Using static resources with Salesforce custom Javascript buttons

share|improve this answer

You could create a VF page that contains all the logic you need, then pass whatever parameters you need from the Account page to this VF page when the user clicks your button. After the actions have taken place, send the user back to the Account record.

Is there a specific reason you need to execute Javascript? Or can all the updates be contained in the VF page controller?

Let me know if you have any questions.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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