[SalesForce] way to write to a Custom Label via Apex

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"

Best Answer

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?