使用Schema类的describesSObjects方法获取描述sObject结果.使用此方法可以通过sObject类型名称描述一个或者多个sObject描述信息。
//sObject types to describe String[] types = new String[]{'Account','Merchandise__c'}; //Make the describe call Schema. DescribeSobjectResult[] results = Schema.DescribeSObjects(types); System.debug('Got describe information for '+ results.size() + 'sObjects.'); //For each returned result, get some info for(Schema.DescribeSObjectResult res : results) { System.debug('sObject Label:'+res.getLabel()); System.debug('Number of fields:'+res.fields.getMap().size()); System.debug(res.isCustom()?'This is a custom object.':'This is a standard object.'); Schema.ChildRelationship[] rels = res.getChildRelationships(); if(rels.size()>0){ System.debug(res.getName() + 'has' + rels.size() +'child relationships.'); } }
首先给大家看一下结果: