You need to sign in to do that
Don't have an account?
prakashedl
Unable to access labels within managed package
I create a managed package myself in one org and installed it in another org. The managed package is in beta status. The managed package has a few custom labels defined that I would like to use it in my apex code in the subscriber's organization. The labels are NOT protected. They have the protected checkbox unchecked. But still I am unable to access them from apex using Label.namespace__labelname. I always get a compilation error "invalid external string name". Am I missing something?
Can you share your code where you are facing the issue
Hi,
You can’t do that in apex, however it can be done in visualforce page using global variable that you can provide the custom label name at runtime.
The following example illustrate this :
//-------------------- Controller-----------------------
public class MyController
{
public String mylabel{get; set;}
public MyController()
{
mylabel='Test_label'; // provide custom label name as you have, in my case it is Test_Label
}
}
//----------------VF Page ------------------------
<apex:page Controller="MyController">
<apex:outputText> {!$Label[mylabel]} </apex:outputText>
</apex:page>
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Label.namespace.labelname
JP12345 was correct! I had the same problem and using a dot instead of a doubble underscore fixed the issue.
Label.namespace__labelname --> change to --> Label.namespace.labelname