0

In my controller I have a List of string. This list contains The Object Name, and the Field Name. So, I need to get the "Label" Name of this fields.

so Is there a way to get parent field name(lable) using describe call

like this:

Map<String, SobjectField> fieldMap = Contact.getsObjectType().getDescribe().Fields.getMap();
System.debug('**********'+fieldMap.get('Account.Name').getDescribe().getLabel());

but it is throwing an error

system.nullpointerexception

1 Answer 1

1

Looks like a Contact or Opportunity Object (Account.Name) so this example will get you that:

String str = 'Account.Name';
String[] obj_fld = str.split('\\.');
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(obj_fld[0]);

String lbl = targetType.getDescribe().fields.getMap().get(obj_fld[1]).getDescribe().getLabel();
system.debug(logginglevel.error,lbl);

You can optimize / error trap as you see fit.

2
  • thanx for ur reply sir but i need account name field label from contact on global describe to contact
    – Tanmay
    Feb 27, 2015 at 8:08
  • and also i need owner name label of contact using global describe
    – Tanmay
    Feb 27, 2015 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .