Is it possible to get a map, in either Apex or using visualforce remoting, of all custom labels? If not does anyone know of the easiest way to access custom labels from javascript?

Right now we have a 1000 line long visualforce js page that is mainly for defining custom labels as javascript objects and it would be nice if we could shorten that code a bit.


2 Answers 2


Getting all of them requires use of the Metadata API. You can access a known one via Javascript, however, by just merging it in. Escaping recommended.

var mylabel = "{!JSINHTMLENCODE($Label.MyLabel)}";

I think you can do this. In one remote action, you get all custom labels and put them in a map with key - value pair like below code:

Map<String, String> customLabelMap = new Map<String, String>();
map.put('ActionNotFound', Label.ActionNotFound);

Hope it helps you :)

  • This would still require me to type each an every label by hand. We have over 1000 custom labels and I am looking to see if there is a way to do this dynamically
    – watzon
    Commented Aug 12, 2016 at 20:04
  • Ok, then I would recommend to check the link, provided by @Adrian Larson Commented Aug 13, 2016 at 4:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .