Tuesday, September 3, 2019

Custom Label : Fetch all Custom Label Information using Tooling API

Considering the organization which have huge metdadata, its very difficult to fetch custom label information using Metadata API. When I tried using Metadata API in org which has more than 15000 custom label, then I was getting "IO Exception: Exceeded max size limit of 6000000" error.

CustomLabel is available in Tooling API and can be used to get all CustomLabel Information. With single callout, REST API return 2000 records and then provide "nextRecordsUrl" attribute which contain URI for next set of custom label.

I have created below code snippet which can be used to fetch all custom labels in csv file. User will receive email with attachment which contains Custom Label Id, Name and Value.

After saving this apex class, run below script in developer console and you will receive email with csv file with all custom label information.

SK_CustomlabelUtility.fetchAllCustomLabels();

Below is snapshot of csv file:



This utility can be helpful to take backup of custom labels in sandbox or production or find dependency or reference of any metadata component like fields in custom label.

Hope this will help!!

Looking forward for everyone comments and feedback.