Skip to main content
Adding reference.
Source Link
Kris Goncalves
  • 22.8k
  • 8
  • 35
  • 72

I wanted to retrieveretrieved the details using the Metadata APIapex-mdapi. Anyway, you can use the belowExample code below:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);

I wanted to retrieve the details using the Metadata API. Anyway, you can use the below code:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);

I retrieved the details using the apex-mdapi. Example code below:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);

I wanted to retrieve the details using the Metadata APIMetadata API. AnywaysAnyway, you can use the below code:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);

I wanted to retrieve the details using Metadata API. Anyways, you can use the below code:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);

I wanted to retrieve the details using the Metadata API. Anyway, you can use the below code:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);
Source Link
nica
  • 1.5k
  • 3
  • 20
  • 43

I wanted to retrieve the details using Metadata API. Anyways, you can use the below code:

List<String> labels = new List<String>{'Demo1'};

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

Map<String, String> valuesByKey = new Map<String, String>();
MetadataService.Translations translations = (MetadataService.Translations) service.readMetadata('Translations',
                new String[] { 'en_US' }).getRecords()[0];
for(MetadataService.CustomLabelTranslation customLabelTranslation : translations.customLabels) {
    if (labels.contains(customLabelTranslation.name)) {
        valuesByKey.put(customLabelTranslation.name, customLabelTranslation.label);
    }
}
System.debug(valuesByKey);