1

Getting only phone fields name of a particular object. I am using Js remoting technique in my visualforce page. How to get only the fields that are of type Phone?

1

3 Answers 3

2

If you want to get all the fields of a certain object, for instance, Account, then use the Schema namespace:

SObjectType accountType = Schema.getGlobalDescribe().get('Account');
Map<String,Schema.SObjectField> accountFields = accountType.getDescribe().fields.getMap();

Afterwards, just iterate through the SObjectFields and use the getType() method to filter them. Check up the documentation here.

2

Try to use Remote Objects, like as follows: Error in retrieving remote objects

The Remote Objects allow us to specify fields to be retrieved and do not require any odd service-side implementation:

<apex:remoteObjects >

    <apex:remoteObjectModel name="User" fields="Id, FirstName, LastName, Email"/>

</apex:remoteObjects>  
0

to get field type from object field use following code

Map<String, Schema.SObjectType> objectMap =Schema.getGlobalDescribe();

for( string obj : objectMap.keySet()){

Map<String,Schema.SObjectField> objFieldMap = objectMap.get(obj).getDescribe().fields.getMap();
for(string field : objFieldMap.keySet()){

    Schema.DescribeFieldResult dfr = objFieldMap.get(field).getDescribe();          
    system.debug('*********************'+dfr.getType());        
}

}

now you can get a which type of you want

Thank you, Amol Salve Salesforce Developer

You must log in to answer this question.

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