Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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… – sfdc Jun 9 '14 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 '14 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 '14 at 19:08
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 (…) although it is not the official answer. I used the method given there by Patlatus. – Jagular Jun 9 '14 at 20:18
@Jagular also a valid approach. The best tools all depend on your use case. – ca_peterson Jun 9 '14 at 21:03

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

share|improve this answer

Your Answer


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.