Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- How to check the field data type of the object in ...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to check the field data type of the object in apex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-14-2012 03:31 PM
Actually i want to check whether if a field is of lookup type and do something if yes.
i tried the following
String ltype='Lead';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(ltype);
Map<String, Schema.SObjectField> lfieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: lfieldMap.keySet()) {
//It provides to get the object fields label.
String lfieldLabel = lfieldMap.get(fieldName).getDescribe().getLabel();
//It provides to get the object fields data type.
Schema.DisplayType lfielddataType = lfieldMap.get(fieldName).getDescribe().getType();
if(lfielddataType==Schema.DisplayType.ID)
system.debug(':::::::::::lfieldType'+lfielddataTyp
system.debug(':::::::::::::::+lfieldLabel'+lfieldL
}
but is displaying all types
any suggestions
Re: How to check the field data type of the object in apex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-16-2012 10:54 PM
Hi Raj,
you can get object field type by using the following code.......
Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get('Account').getDescr
for(String s : objectFields.keySet())
{
Schema.DescribeFieldResult lfieldLabel = objectFields.get(s).getDescribe();
Schema.DisplayType dType = lfieldLabel.getType();
string fieldType = String.ValueOf(dType);
system.debug('******'+fieldType);
}
Re: How to check the field data type of the object in apex
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-16-2012 11:03 PM
string s='Lead';
Map < String, Schema.SObjectType > m = Schema.getGlobalDescribe();
Schema.SObjectType sT = m.get(s);
Schema.DescribeSObjectResult r = sT.getDescribe();
Map<String, Schema.SObjectField> mapData = r.fields.getMap();
for(Schema.SObjectField sField:mapData.values()){
F= sField.getDescribe();
//getType will return the field Data Type like Double, Phone etc
string sdataType= string.valueOf(F.getType());
if(sdataType=='REFERENCE'){
//do something
}else{
//nothing
}
}
you need to check condition 'REFERENCE'. see the above smaple. If you want to have check and condition for custom lookup then you need to add more condition as string sBoolean=string.valueOf( F.isCustom()); // will return True/False.
Hope this will help.

