3

1.When I query the objects using Schema.getGlobalDescribe() I get wierd objects like "ApexTestQueueItem", "Announcement", "AccountContactRole", "Account_Escalation__c". I basically only want the standard objects and custom object. How can I filter out other objects?

2. I need the LastModifiedByName, LastModifiedDate, CreatedByName, CreatedDate, is the field being tracked? (TrackHistory), URL of the field information detail page. I'm looking at the DescribeFieldResult Class but it doesn't provide these things.

3. If I use getType() method. I can only get the fieldtype "REFERENCE", but I want to know if it's a lookup or master-detail field. What can I do?

global with sharing class MetadataExtractor {
@RemoteAction
global static List<fieldDescribe> getObjectsAPINames(){
    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
    Set<String> setKeys = gd.KeySet();
    List<string> lstKeys = new List<string>();
    lstKeys.addAll(setKeys);
    lstKeys.sort();
    List<fieldDescribe> res = new List<fieldDescribe>();        
    for(string key : lstKeys){
        if(!key.Contains('__')||key.Contains('__c')){
            Schema.SObjectType sobjType = gd.get(key);
            Schema.DescribeSObjectResult dsr = sobjType.getDescribe();
            if(dsr.isCreateable()){
                string ObjectAPIName = dsr.getName();
                Map<String, Schema.SObjectField> m = dsr.fields.getMap();
                for(String key1 : m.KeySet()){
                    Schema.DescribeFieldResult dfr = m.get(key1).getDescribe();
                    fieldDescribe fd = new fieldDescribe();
                    fd.ObjectAPIName=ObjectAPIName;
                    fd.fieldLabel=dfr.getLabel();
                    fd.fieldAPIName=dfr.getName();
                    fd.fieldType=String.ValueOf(dfr.getType());
                    fd.fieldHelpText=dfr.getInlineHelpText();
                    res.Add(fd);
                }
            }

        }
    }
    return res;
}

global class fieldDescribe{
    public string ObjectAPIName {get;set;}
    public string fieldLabel{get;set;}
    public string fieldAPIName{get;set;}
    public string fieldType{get;set;}
    public string fieldHelpText{get;set;}
}
}

Thanks

1 Answer 1

1

The first is a doozy. Each object as an isCustom property, which you can use to identify custom object. However, those objects you mention are all Standard as well, so there is no clear way to identify them. You can try narrowing it down by evaluating isCreatable (though that will depend also in the user's permissions)

I recommend you avail yourself to the workbench (https://workbench.developerforce.com/describe.php) and explore what you can and cannot do in your org.

As to Questions 2 and 3, I am not exactly sure (and I cannot do the proper research at the moment). I will leave those other answers to colleagues in the forum

You must log in to answer this question.

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