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
Rakesh KumarRakesh Kumar 

How can i get all Object's field(custom and standard) in single click ??

Hi techie,

 

I am looking for apex code which can get all objects field in single click .

I can get all custom fields according to particular objects but i cant able to get all custom and standard fields in single click.

Is there any way to get all fields in single select or click?

 

 

Thanks in advance.

Rakesh

 

Chris DaviesChris Davies

You can make a Describe call to retrieve the metadata.

 

I suggest that you create a visualforce page with a dynamic piclist of sobjects, and a custom button with an apex method that returns all the available field names for that object.

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describesobject.htm

Rakesh KumarRakesh Kumar

Hi Chris,

 

Thanks for reply.

 

I can get list of all objects and according to selected object i can get all fields but my requirement is not get specific Object's Field i would like to get all object's field in single array.

 

I hope it will make sense about my requirement.

 

Thanks

Rakesh

Chris DaviesChris Davies

Hi Rakesh,

 

This is normally how you would retrieve the sObject Fields:

 

// Get the list fo Fields for the selected object
    public void getObjectFields(){

        childObjectFields = new List<SelectOption>();
        
    Map<String, Schema.SObjectField> mapFields = Schema.getGlobalDescribe().get(YOURSOBJECTNAME).getDescribe().fields.getMap();
        
    List<String> sortedKeyset = new List<String>();
        
    for (String fieldName: mapFields.keyset()){
        sortedKeyset.add(fieldName);
        }
        
    sortedKeyset.sort();
        
    for (String fieldName: sortedKeyset){
            childObjectFields.add(new SelectOption(fieldName, fieldName));
        }
        
    return;
    }

 

You may have to loop through all the sobjects and add they are fields to the map.