{"id":107,"date":"2013-10-05T15:11:38","date_gmt":"2013-10-05T23:11:38","guid":{"rendered":"http:\/\/www.bridgefarmconsulting.com\/blog\/?p=107"},"modified":"2013-10-05T15:15:09","modified_gmt":"2013-10-05T23:15:09","slug":"new-schema-method-for-describing-multiple-sobjects","status":"publish","type":"post","link":"https:\/\/www.bridgefarmconsulting.com\/blog\/new-schema-method-for-describing-multiple-sobjects\/","title":{"rendered":"New Schema Method for Describing Multiple sObjects"},"content":{"rendered":"<p>If you are building ISV packages on Force.com, you quickly end up needing to do Describe calls on sObjects. Prior to Winter 14, you could either request the Describe results for a single sObject, or get the describe results for all sObjects. Most people then end up writing utility classes to cache those results into a static Map so you could retrieve the results from a Map as you needed them, and not breach any describe call limits.<\/p>\n<p>But in Winter 14, there is a new <a href=\"http:\/\/www.salesforce.com\/us\/developer\/docs\/apexcode\/Content\/apex_dynamic_describeSObject.htm\" target=\"_blank\">Schema Method<\/a> which let&#8217;s you pass in a string [] of sObjects names you want describe results for, and get back an Schema.DescribeSobjectResult [] for the results, which will prove really helpful when you need the results for two or three sObjects and a full describe seems like overkill. As ever with new Force.com releases, I also now get to go back and update all those utility classes I built\/borrowed from others&#8230;<\/p>\n<p>Here&#8217;s the sample code from the docs<br \/>\n<code><br \/>\n\/\/ sObject types to describe<br \/>\nString[] types = new String[]{'Account','Merchandise__c'};<br \/>\n\/\/ Make the describe call<br \/>\nSchema.DescribeSobjectResult[] results = Schema.describeSObjects(types);<br \/>\nSystem.debug('Got describe information for ' + results.size() + ' sObjects.');<br \/>\n\/\/ For each returned result, get some info<br \/>\nfor(Schema.DescribeSobjectResult res : results) {<br \/>\nSystem.debug('sObject Label: ' + res.getLabel());<br \/>\nSystem.debug('Number of fields: ' + res.fields.getMap().size());<br \/>\nSystem.debug(res.isCustom() ? 'This is a custom object.' : 'This is a standard object.');<br \/>\n\/\/ Get child relationships<br \/>\nSchema.ChildRelationship[] rels = res.getChildRelationships();<br \/>\nif (rels.size() &gt; 0) {<br \/>\nSystem.debug(res.getName() + ' has ' + rels.size() + ' child relationships.');<br \/>\n}<br \/>\n}<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are building ISV packages on Force.com, you quickly end up needing to do Describe calls on sObjects. Prior to Winter 14, you could either request the Describe results for a single sObject, or get the describe results for all sObjects. Most people then end up writing utility classes to cache those results into [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,8,9],"tags":[],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-apex","category-utilities","category-winter-14"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":2,"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/posts\/107\/revisions\/109"}],"wp:attachment":[{"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bridgefarmconsulting.com\/blog\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}