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
AvLavAvLav 

How can I get the standard object field NAME?

Hy all!

I need the standard object field NAME (not the value). For example: Accounts -> Account name, account number, accoutn owner, etc.

I want to use this name in a select, but I don't know how can I get this information.

Is anybody know?

Best Answer chosen by Admin (Salesforce Developers) 
MiddhaMiddha

This should work:

 

 

public List<SelectOption> getCateg() { List<SelectOption> options = new List<SelectOption>(); Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();Schema.SObjectType leadSchema = schemaMap.get('Account');Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();for (String fieldName: fieldMap.keySet()) { options.add(new SelectOption(fieldName, fieldName)); } return options;}

 

 

 

 

All Answers

Shailesh DeshpandeShailesh Deshpande

go to Setup --> Customize -->  Accounts --> Fields

 

Click on the field you want...you'll get the field name to be used in query...

AvLavAvLav

Ok, I know where  I can find the field name. But I need it in apex code. for example with soql or something similar.

 

Shailesh DeshpandeShailesh Deshpande
Can you elaborate what you are trying to do? I did not get what you are trying to say by saying "need it in apex code"...
AvLavAvLav

I have two select. The first contain the standard objects name (Accounts, contatcd, lead). The second is contain the object field name depends on what objest you choose.

For example in MSSQL you can use this:

SELECT table_name=sysobjects.name, column_name=syscolumns.name, datatype=systypes.name, length=syscolumns.length FROM sysobjects JOIN syscolumns ON sysobjects.id = syscolumns.id JOIN systypes ON syscolumns.xtype=systypes.xtype WHERE sysobjects.xtype='U' ORDER BY sysobjects.name,syscolumns.colid

 


 

MiddhaMiddha

You can describe an object and get all the field properties of that object, including label API name etc.

 

example:  SObjectType objToken = Schema.getGlobalDescribe().get('Account');

 

APEX document explains it in much detail. Hope this helps.

 

/G 

 

AvLavAvLav

I want something similar. But How can I display this information?

Is there any chance to make it with a simple query (return with a list of string).

I have a select. It's fill dynamically:

public List<SelectOption> getName() { List<SelectOption> options = new List<SelectOption>(); for (sObject object : [select id, Name from sobject]) { String value = object.Name; options.add(new SelectOption(value, value)); } return options; }

I need to fill my selectoption the same way, but the header of the column instead of the value.


 

MiddhaMiddha

No, You cannot query "sObject". SOQL queries should have a concrete sObject like "Account" etc.

 

But the functionality required can easily be achieved using describe calls, stated in my previous post.

 

Any specific reason that you dont want to use describe calls? 

 

/G 

MiddhaMiddha

This should work:

 

 

public List<SelectOption> getCateg() { List<SelectOption> options = new List<SelectOption>(); Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();Schema.SObjectType leadSchema = schemaMap.get('Account');Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();for (String fieldName: fieldMap.keySet()) { options.add(new SelectOption(fieldName, fieldName)); } return options;}

 

 

 

 

This was selected as the best answer
AvLavAvLav

OMG! That's work! Thank you very much. I tried to make it all day yesterday, but I failed.

You are the best ;)