Thursday, May 24, 2012



[You can see this blog for a more elegant solution ]

This was unknown to me and in past months I tried hard to use Datetime field in Dynamic SOQL query, well after doing lots of permutations and combinations I finally figured it out! which I though was not possible.

Well I guess this is worth sharing so here it is.

You can compare any Datetime field in Dynamic SOQL where query! Just keep in mind the format should be correct. You can use the format method to format datetime field like this where System.Now() is my Datetime field.

System.Now().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\''));


OR




DateTime dt = System.Now();//initialize datetime with current datetime

String formatedDt = dt.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');//format the datetime to make it Dynamic Soql ready


So a sample query to extract all the Accounts where the CreatedDate is less than Today will be


DateTime dt = System.Now();//initialize datetime with current datetime
String formatedDt = dt.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');//format the datetime to make it Dynamic Soql ready
Database.query('Select Id FROM Account WHERE CreatedDate<'+formatedDt);



Wednesday, May 23, 2012


Well Summer 12 is approaching with lots of new enhancements including fieldset describing feature from within apex.This was most awaited feature for me because have done a lot work around to achieve the same result.
Thanks to Abhinav Gupta from whose blog(http://www.tgerm.com/2012/01/recordtype-specific-picklist-values.html) I actually got Idea how to develop these feature. Sometime back Abhinav wrote about describing picklist based on recordtype, I took the code from there and made some changes in the classes and Eureka! a fieldset describer is at your service.

Well since Summer 12 is approaching very fast and after that this will not be of any use,So this for those user who are still stuck in Spring 12 and need a work round to get a List of field names that a field set contains. Well you can install the package from this link https://login.salesforce.com/packaging/installPackage.apexp?p0=04t900000009eGV

It mainly contains two classes. A visulaforce controller to generate a page using the fieldset and parsing the response and another main class to which we send Field Set name and Object name.

How to describe a fieldset?
Its very easy just follow the below code.

List<String> fieldNameList = FieldSetDescriber.describeFieldSet('<Your Object Name>','<Your Field Set Name>');



Tuesday, May 22, 2012


Well few days ago I came across a requirement where on button click user should be asked for confirmation about the action in a modal window. Well we don't have such component in Visualforce!. But hey! Wait! I guess the jquery has it! Why dont we use that one ?

So started mixing Visualforce with Jquery and Result? A modal dialog box!


Well Don get scared its very easy to implement!

Just go to apex/showDialog page for demo and press the showDialog button.

To summarize you can just open a modal window by just calling the openDialog method included in the showDialog page,make sure that you include necessary files while you implement the same in your VF page.

Exp : openDialog('This is a custom dialog','Alert')" ;
Where the first argument is the dialog body and the second is the Dialog title.