Extracting Schemas from SalesForce

Nerding on November 26th, 2008 No Comments

It took me way too long to figure out how to get SalesForce to export schema information on an object.  It seemed so tantalizingly easy – the salesforce.schema file is right there in the IDE but it’s a placeholder for a dynamically updated widget…that won’t export the XML it clearly contains.

So, I learned about Maps, SObjectFields, and some other stuff.  I might have even helped this person out, who posted today about nearly the same thing.

Map<string,Schema.SObjectField> M =
  Schema.SObjectType.Organization_Detail__c.fields.getMap();
Set s = M.keySet();
for (String s1 : s) {
  SObjectField f = M.get(s1);
  Schema.DescribeFieldResult d = f.getDescribe();
  System.debug(logginglevel.INFO,d.getName() + ',' + d.getLabel());
}

Execute the above as anonymous, and you should get a comma separated set of names and labels.  I’m in no mood to figure out how to suppress the 20081127030828.685:AnonymousBlock: line 6, column 3: that it poops out, so I’ll trim it down in TextPad.

Tags: , , ,

No Responses to “Extracting Schemas from SalesForce”

Leave a Reply