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
Mayank Agarwal 5Mayank Agarwal 5 

Object label name from strings?

Hello,

I have a custom object 'Jobs__c' which contains a picklist field 'Level__c' which containsapi namesof objects as: 'Account', 'Contact', 'Position__c','Applicants__c', 'Skills_sets__c'.

I want to obtain the object label names based on the 'Level__c' values and used them in custom piclist on Visualforce Page.

Please suggest a way to accomplish this.

Thanks,
Mayank
Best Answer chosen by Mayank Agarwal 5
Vatsal KothariVatsal Kothari
Hi Mayank,

You can refere below code:

public List<String> objLabelName {get;set;}
List<String> objName = new List<String> { 'Account', 'Contact' , 'Position__c'};
    for(String str : objName){
        List<Schema.DescribeSObjectResult> describeSobjectsResult = Schema.describeSObjects(new List<String>{str});
        System.debug(describeSobjectsResult);
        String objectLabel = describeSobjectsResult[0].getLabel();
        System.debug('***'+objectLabel);
        objLabelName.add(objectLabel);
    }

now you can use objLabelName iside you VF page.

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

All Answers

Vatsal KothariVatsal Kothari
Hi Mayank,

You can refere below code:

public List<String> objLabelName {get;set;}
List<String> objName = new List<String> { 'Account', 'Contact' , 'Position__c'};
    for(String str : objName){
        List<Schema.DescribeSObjectResult> describeSobjectsResult = Schema.describeSObjects(new List<String>{str});
        System.debug(describeSobjectsResult);
        String objectLabel = describeSobjectsResult[0].getLabel();
        System.debug('***'+objectLabel);
        objLabelName.add(objectLabel);
    }

now you can use objLabelName iside you VF page.

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
This was selected as the best answer
AshlekhAshlekh
Hi,

Please go through the below link and read properly you will full idea about describe call in salesforce which help you a lot
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describeSObject.htm
Mayank Agarwal 5Mayank Agarwal 5
Hello Vatsal,

Thanks for the response.

It helps me a lot.

Thanks,
Mayank Agarwal 5Mayank Agarwal 5
Hello Ashlekh,

Thanks for your response also.

Thanks,