Delights of Dynamic DML

I have been busily working on a cool little demo app taking advantage of the some the recently released new toolkits and products like the Facebook Toolkit and Force.com Sites. Often it is these marketing friendly features that get most of the buzz, but once you get down to it and start writing applications on the platform you quickly realize the benefits of one of the force.com’s unsung heros: Dynamic DML.

One of the features I use the most is the ability to retrieve an object, modify it’s contents and update all within a few lines of code:

Sobject result = Database.query(‘select AccountNumber from Account limit 1’);
//we can do what we want with the account number now
Object o = result.get(‘AccountNumber’);
//or we can update the results
result.put(‘AccountNumber’, ‘abc’);
//and commit it back to the database
update result;

Thought that was easy, what about if we wanted to set or get foreign keys? No problem:

SObject myContact = Database.query(‘select id, FirstName, AccountId, Account.Name from Contact limit 1’);
SObject myAccount = myContact.getSObject(‘Account’);

With Dynamic DML at my fingertip I am rapidly completing my demo quicker than ever before and should be in a position to post it soon.

For more information on Dynamic DML check out the docs

Published
November 12, 2008
Topics:

Leave your comments...

Delights of Dynamic DML