function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LakshmanLakshman 

Help me choose best!

Hi All,

 

I want to declare some constants which will be used by my Apex class. I find two approches to it.

 

1) Custom Settings

2) Global class and declare static varible in the that class. Then access them in my desired class.

 

Let me know which one would be better.

Thank you!

 

Regards,

Lakshman

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I'd use option 1 if you want administrators to be able to change the constant (for example, if they contained record type names that may change going forward).

 

I'd use option 2 if you are simply trying to avoid hardcoding magic strings/numbers into your classes.

All Answers

bob_buzzardbob_buzzard

I'd use option 1 if you want administrators to be able to change the constant (for example, if they contained record type names that may change going forward).

 

I'd use option 2 if you are simply trying to avoid hardcoding magic strings/numbers into your classes.

This was selected as the best answer
LakshmanLakshman

I am savind values which would be used while sending email like To address, Email template, such kind of things.

Administrators will edit this value. I think option 1 would be better. Let me know your thoughts.

Ankit AroraAnkit Arora

Indeed option 1 is best between the two, but you can also consider creating custom labels if you are talking about strings.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

LakshmanLakshman

Thats also a good suggestion Ankit. But I think in future there can be name value pair. So I would go for Custom Settings.

 

Regards,

Lakshman

Ankit AroraAnkit Arora

If there is a name value pair then you should go for custom settings. I have implemented same using custom setting in many of my projects.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page