I've multiple Visualforce pages using Google Map, till now I am not using any Google Map Javascript API Key key while referencing the Google Map script.

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>

Now due to daily request limit exceeded, I am planning to use API key while referencing the Google Map script, So I've now following 4 options and need help to figure out which option is most suitable

  1. Simply hard-code API key in all pages, but it will be time-consuming in future if I've to change the API key.
  2. Use of Hierarchy custom setting with API key field in it and as we can directly use "Hierarchy Custom Setting" in the Visualforce page, I have to change the API Key in only place. But I think use case of "Hierarchy Custom" setting is different, so using Hierarchy custom setting just because it is directly accessible in the Visualforce page seems wrong.
  3. I can use List custom setting but among multiple Visualforce pages, some pages don't have controller or extension class associated. As List custom setting is not directly accessible in the VF pages, we have to return the value from Apex class. Just to return API key from the List custom setting, creating controller or extension class is also seems unnecessary work.
  4. Use of custom label as it is directly accessible in the Visualforce pages.

Thank you in advance.

  • I'd go for option 4. – rael_kid Mar 16 '17 at 7:56
  • +1 its a very good question, I would avoid use of a custom label and have seen my fellow developers using it for everything as its easy to use in VF page without any/or minimal exception handling. – Raul Mar 16 '17 at 8:36

I would use a List Custom setting. As its really a setting not Label.

Hierarchical custom setting should be used when we setting changing per user or profile.

Custom labels is advised to to store labels as name suggests.

To solve your issue with the controller:

  • One of a many trick, would be to use a base/parent class by extending it with use of extends keyword.

Base class to fetch API key would look like:

public virtual class GoogleIntegrationService {
    public String getApiKey() {
        return 'API Key';

Controller class extends base class to fetch API key would look like:

public class GeoLocationCtrl extends GoogleIntegrationService {


You can directly use the base class as a controller which only have reusable code.

<apex:page controller="GoogleIntegrationService">

And can use a controller to a page having custom functionality, which still uses apiKey from parent class.

<apex:page controller="GeoLocationCtrl">

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.