function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DevelopersDevelopers 

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.

 

Regards,

Phanikumar

Devendra@SFDCDevendra@SFDC

Hi,

 

Please refer below blog,

 

http://th3silverlining.com/2009/06/10/dynamic-custom-labels/

 

Hope this helps :)

 

Thanks,

Devendra

$hwet@$hwet@
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.
 
TruptiTrupti
Hi,
Can you share code where you are getting error?
Also if you want to retrieve value from custom label use: Label<Label_Name>

Thanks
Deepali KulshresthaDeepali Kulshrestha
Hi,

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


 
JLA.ovhJLA.ovh
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
Vijayendra PatilVijayendra Patil
SELECT Id, Name from CustomLabel
-- enable Use Tooling API in query editor