Sunday, February 26, 2012

Metadata API

Exploring the Metadata API

Well, I started exploring Metadata API after a long pause of more than 2.5 years (last time I touched Metadata APIs was early 2009).

According to SFDC .. "Use the Metadata API to retrieve, deploy, create, update or delete customization information, such as custom object definitions and page layouts, for your organization. This API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself.
To use the Metadata API, your organization must use Enterprise Edition, Unlimited Edition, Free Edition, or Developer Edition.

Development Platforms
The Metadata API supports both file-based and CRUD-based development.
File-Based Development
The declarative or file-based asynchronous Metadata API deploy() and retrieve() calls deploy or retrieve a .zip file that holds components in a set of folders, and a manifest file named pa
ckage.xml.
CRUD-Based Development

The CRUD-based asynchronous Metadata API calls create(), update(), and delete() act upon the metadata components in a manner similar to the way synchronous
API calls in the enterprise WSDL act upon objects."

This opens up a whole new world of integration possibilities with any salesforce.com org.
We can virtually change the configuration - add/ delete custom objects, fields etc using simple CRUD based calls. Isn't that amazing !


Now here comes the sad part - CRUD based calls can

not be used to create/update/delete the custom coding components like apex class, apex trigger etc. Wonder when Salesforce.com is going to give that to us?
I tried still doing that and it gave "INVALID_TYPE: This type of object is not available for this organization" (as if it were a permissions error..well still hopeful that this may change within the next few releases.

Another thing I would just love to have on Metadata
API is a way to retrieve active/inactive state of components and preferably change them too. That is it would be great if i could just query all the triggers in my org and see if they are active or inactive and then them too. May be SFDC could enhance their "ListMetadataQuery" function to do the same

Updating UserTerritories via Code


It happens only on Salesforce.com.
Many objects which cannot be updated by Apex are available for updates by web-services. e.g. UserTerritories.
These are still updateable by Webservices API, Ajax Toolkit.
So essentially other systems utilizing SFDC webservices can update it, but not Apex which and is interpreted, executed, and controlled entirely by the Force.com platform.