+ Start a Discussion

How to query the records from custom label object?

Hi Friends,


I need to know how to the query the records from custom label object. Is it possible to query the data from this object? As we do the same from other objects like Account, Contact, ......

We can use labels in our controller, like Label.<Label_Name>.


while i am trying to query the data from customLabel, it is throwing error like :


"line 1, column 20: sObject type 'CustomLabel' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names."


Please help me in this, how to use this object in apex controller.


Thanks in advance.







Please refer below blog,




Hope this helps :)




Hi Phanikumar,

For getting the custom label in apex class use Label.<label_name>
for example:
Msg : string variable
Invalid_Usertrest: name of the label.
Msg = Label.Invalid_Usertrest

Kindly let me know if it helps.
Can you share code where you are getting error?
Also if you want to retrieve value from custom label use: Label<Label_Name>

Deepali KulshresthaDeepali Kulshrestha

Custom labels are not accessible via SOQL. You will need to use the Metadata API to complete the query you are looking for.

I would suggest taking a look at Andrew Fawcett's Apex Wrapper Salesforce Metadata API.(https://github.com/financialforcedev/apex-mdapi).

With the API you can query the CustomLabels metadata type to get the information you are looking for.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha

You can use the tooling API too
SELECT Id,Name,MasterLabel,Value,IsProtected,Category,Language,NamespacePrefix,ManageableState,CreatedDate,CreatedById,LastModifiedDate,LastModifiedById FROM ExternalString LIMIT 200

Sagar Nagvekar 29Sagar Nagvekar 29
In Query Editor in Developer Console, check the checkbox for "Use Tooling API" and then execute this query in the Query Editor to locate custom labels which have "Please attach your" in their content :-
Select id, name, value from CustomLabel where value like '%Please attach your%' limit 5