You need to sign in to do that
Don't have an account?
AvLav
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?
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
go to Setup --> Customize --> Accounts --> Fields
Click on the field you want...you'll get the field name to be used in query...
Ok, I know where I can find the field name. But I need it in apex code. for example with soql or something similar.
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
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
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.
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
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;}
OMG! That's work! Thank you very much. I tried to make it all day yesterday, but I failed.
You are the best ;)