Sunday 6 September 2015

Global Describe in salesforce



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

Set<String> setSobjets = new Set<String>();

for(Schema.SObjectType d :mapSchemaSobjectType.values())
{
       Schema.DescribeSObjectResult dSobject = d.getDescribe();
       setSobjets.add(dSobject.getName());
}

setSobjets This set will contain all the SObject name.

-----------------------------------------------------------------------------------------------------

Map<String, Schema.SObjectType> mapSchemaSObjectType = Schema.getGlobalDescribe();
Set<String> standardObjects = new Set<String>();
Set<String> customObjects = new Set<String>();
for(Schema.SObjectType objSchemaSobjectType : mapSchemaSObjectType.values())
{
    Schema.DescribeSObjectResult objResult = objSchemaSobjectType.getDescribe();
    if(!objResult.isCreateable())
      continue;
    if(objResult.isCustom() == false && objResult.getRecordTypeInfos().size() > 0)
        standardObjects.add(objResult.getName());
    else if(objResult.isCustom())
        customObjects.add(objResult.getName());
}

standardObjects - Contains set of standard objects.
customObjects - Contains set of Custom objects

No comments:

Post a Comment