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"

  • also found another link developer.salesforce.com/forums/…
    – sfdc
    Commented Jun 9, 2014 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? Commented Jun 9, 2014 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
    Commented Jun 9, 2014 at 19:08

2 Answers 2


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?

  • 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
    Commented Jun 9, 2014 at 20:18
  • @Jagular also a valid approach. The best tools all depend on your use case. Commented Jun 9, 2014 at 21:03

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .