Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is there a way to write to a Custom Label via Apex? The online documentation doesn't outright say that you can't, but I'm guessing it's called a 'custom label' rather than a 'custom variable' for a reason.

My naive efforts to do

Label.myLabel = 'foo';
System.Label.myLabel = 'bar';

result in the following error:

"Error: Compile Error: Expression cannot be assigned at line 12 column"

share|improve this question
    
also found another link developer.salesforce.com/forums/… –  sf.dev Jun 9 at 18:55
    
I'm curious to hear of the use case for this. Is there any way you can just use a variable for this rather than a label? –  Jesse Altman Jun 9 at 18:56
    
I ended up using a different method, but here's my situation. I have a scheduled job that schedules 5 other jobs. Each of the five needs a parameter (or I have 5 nearly identical pieces of code to maintain). Passing info along through a custom label seemed worth a try. –  Jagular Jun 9 at 19:08
add comment

2 Answers 2

up vote 4 down vote accepted

Custom labels can only be created/modified via the setup web interface or via the metadata API. There's no direct way to invoke metadata API operations from apex other than some 3rd party libraries to make webservice calls.

That probably doesn't do what you want however, and it sounds like custom labels aren't an optimal fit for your use case. Have you looked at using list custom settings?

share|improve this answer
    
The solution I ended up using is on this question (salesforce.stackexchange.com/questions/14634/…) although it is not the official answer. I used the method given there by Patlatus. –  Jagular Jun 9 at 20:18
    
@Jagular also a valid approach. The best tools all depend on your use case. –  ca_peterson Jun 9 at 21:03
add comment

I think you can't assign the expression to custom label.I found an idea related to this.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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