I have existing code which contains upto 20 hard coded messages(info, error etc.) inside my lightning JS controller.

I am confused whether to use custom labels or custom settings as part of code improvement.

I don't need any language translations in my project.

Can someone help me to provide the best practice to be followed in this situation?

up vote 3 down vote accepted

If you have many hard coded messages at your component then better to use Custom Settings, as you can cache those messages. All the entries are stored as records as opposed to individual components like custom label.

Custom Labels are good if you have translations at your org and trying to remove hard coded values. Every label will be treated as separate components.

Accessing the Custom Label requires less coding and can be done on client side itself as follows:

$A.get("$Label.namespace.labelName")

Whereas to use Custom setting you need both client and server side coding. Refer How to Access a Hierarchy Custom Setting from Lightning Component.

I think the best thing to do is to created custom labels because custom settings needs to be queried.

  • While it is true that custom settings can be queried, you don't need to query for them. The getInstance() or getAll() methods (inside an @auraenabled apex method) would work. – Derek F Aug 10 at 12:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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