0

In my apex class there is a String as 'India' . I have to replace it by constant. I dont know how to do that.

Please provide answer for this...!!

1
  • 2
    It would be easier to help you out if you could add a code sample which explains what you're trying to do.. – Sam Jun 12 '15 at 12:35
3

Alternatively, you could simply create a static final variable. This is a fairly pretty common way of using Constants in code so that you aren't using magic variables.

public class Constants
{
  public static final String DEFAULT_COUNTRY = 'India';
}
0

Here are the Salesforce String methods, Not sure what you are wanting to do. replace the String with what.

Putting the code in will also help

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm

0

You can create a Custom Setting with 'India' as value, and call it in your code like:

MyCustomSetting__c.IndiaConstant__c
0

As Nebula mentions, a Custom Label would be perfect for this.

You can then easily refer to it like so:

$Label.LabelName

This is especially helpful if you are creating a multilingual application, as you can store different translations for the same string and have them appear in the user's native language - but even if you don't have that requirement, they are still a great way of storing information that needs to appear in multiple locations.

For more information, see https://help.salesforce.com/HTViewHelpDoc?id=cl_about.htm&language=en_US

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