You need to sign in to do that
Don't have an account?
waylonatcim
Field Labels
I'm trying to figure out how to access the labels for specific fields in a custom object. The following code works great for this:
The issue is that the field that I want to get the label for is variable. So I want to have more of a lookup function to get the label. Trying
Does not work, since it does not pull 'Analyst__c' from the variable analyst. I tried getting all of the fields from my object so I could cycle through and compare the field name, then pull the label out of the correct one, but Field is apparently an invalid type.
How can I find the label for these fields?
For reference, below is a snippet of my code that shows how I'm getting the fields that I need labels for (it's for history tracking):
Code:
String mylabel = Schema.SObjectType.SFDC_Target_Company__c.fields.Analyst__c.getLabel();
Code:
String analyst = 'Analyst__c'; String mylabel = Schema.SObjectType.SFDC_Target_Company__c.fields.analyst.getLabel();
Does not work, since it does not pull 'Analyst__c' from the variable analyst. I tried getting all of the fields from my object so I could cycle through and compare the field name, then pull the label out of the correct one, but Field is apparently an invalid type.
How can I find the label for these fields?
For reference, below is a snippet of my code that shows how I'm getting the fields that I need labels for (it's for history tracking):
Code:
Public List<List<SFDC_Target_Company__History>> listHistory { get{ if(listHistory == null){ listHistory = new List<List<SFDC_Target_Company__History>>(); List<SFDC_Target_Company__History> tempHistory = new List<SFDC_Target_Company__History>(); for(ID i : projects.keySet()){ tempHistory = [select ParentId,Field,NewValue,OldValue,CreatedDate, Parent.Name from SFDC_Target_Company__History where ParentId = :i and Field != 'created' Order by CreatedDate desc]; listHistory.add(tempHistory); } } return listHistory; } set; }
Some relevant documentation:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describe_objects_understanding.htm
Thanks for the reply, I just had to make one small change to the code you provided and it worked great:
Thanks for your help!