Thursday, August 23, 2012



This Version is no more actively developed and is deprecated. But we have developed two more Alternatives for the same which are much more fun and easy to implement






This is minor change to my Sortable Pageblock Table Component. This change adds some cosmetic changes like the "legendary" up and down arrow to so the direction of sorting.

If you haven't read about this component earlier you can always have a quick glance to my earlier post here .
(You can find details about implementing in the blog)

Demo
You can check the live demo from here(http://blogforce9dev-developer-edition.ap1.force.com/SortablePageblocktable)

Give the Code:
Well you can install the package from here (https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000M3ie)

Screens.




Sunday, August 19, 2012



Well today while trying to retrieve the label of a field dynamically I found a hidden capability of visualforce!
It not only can retrieve the "label" but almost everything that can be retrieved using "DescribeSObjectResult" and "DescribeFieldResult" .

Instead of rushing into the topic proceed step by step.

Example : Dynamically retrieving the label of Account say phone.
<apex:outputLabel value="{!$ObjectType.Account.fields.Phone.label}"/> 

Well we can also retrieve the API name of the field by just changing the "label" with "name"
<apex:outputLabel value="{!$ObjectType.Account.fields.Phone.name}"/> 


Well thats not all you can also get the datatype of the field
<apex:outputLabel value="{!$ObjectType.Account.fields.Phone.type}"/> 

So what we are actually doing here?
Well if we simply write "$ObjectType.Account.fields.Phone" we are actually describing the phone field which is equivalent to "Schema.DescribeFieldResult" now if you see the salesforce doumentation for "Schema.DescribeFieldResult"(http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm). Now if you see the above page there are lots of methods defined like say  "getLength()" you can simple access the value by dropping the "get" and writing :

<apex:outputLabel value="{!$ObjectType.Account.fields.Phone.length}"/> 

How to do this dynamically?

<apex:outputLabel value="{!$ObjectType.Account.fields[fieldName].label}"/> 


Where "fieldName" is the fieldApi Name.

What else we can do?
Well if you check this page (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describesobjects_describesobjectresult.htm) you can almost call every method described in this page. Doing "$ObjectType.Account" actually describes the Account object and now after describing the object you can call almost any of the above methods described in salesforce documentation for "DescribeSObjectResult".

Example 1: Say if I want to retrieve the plural label for sObject "Account" my VF code will be

<apex:outputLabel value="{!$ObjectType.Account.labelPlural}"/>


Example 2 : If I want retrieve the "keyPrefix"

<apex:outputLabel value="{!$ObjectType.Account.keyPrefix}"/>

Like this we can almost get all the properties for a object describe



Friday, August 17, 2012


Well how many times you have tried to use a list variable in a Dynamic SOQL?
We generally use Database.query() ,  which takes a query in string format and returns a List of sObject . The problem comes when want to use "IN" statement or want to use "date/date time" in a Dynamic query . I really tried a lot of combination, formatting the data,escapes etc.But finally was surprised to see if you just include the variable inside the query String, it just works !!!

Wasn't clear enough??

See the below example  which shows how to query all the accounts that are created today:

 
//initialize the Datetime with current time
DateTime now = System.now(); 
//query accounts by merging the variable name inside the query string 
List<Account> accountList = Database.query('SELECT Id FROM Account WHERE CreatedDate =:now'); 




Please Note :  that the variable "now" is included in the string itself.






Monday, August 13, 2012


This Version is no more actively developed and is deprecated. But we have developed two more Alternatives for the same which are much more fun and easy to implement





How many times you have tried to create a Sort-able Page block table?
Well I personally tried the same lot of time but never got a plug n play solution, this always ended up with lots of changes in my controller class.

There are lot of work around Dynamic SOQL,Order by statement, List Sorting etc. Well most of them requires a lot of coding and changes in the visualforce page.
Most of time we need to display just a small list of sortable data ,to implement the same I guess writing apex classes and code is not a good idea.
So I tried writing visualforce component which uses jQuery table sorter to do the job.Well this component is very naive stage and needs some obvious enhancement like, ability to specify which fields to sort, proper images to display the sorting order.

How to use the component?

Parameters
sObjList : List of sObject To display
fieldList : List of field API names to display in the table as column. 

 <c:SortablePageBlockTable sObjList="{!accounts}" fieldList="{!fields}"/>                   



This Version is no more actively developed and is deprecated. But we have developed two more Alternatives for the same which are much more fun and easy to implement






Demo.

You can check the live demo from here(http://blogforce9dev-developer-edition.ap1.force.com/SortablePageblocktable)

Package/Installation
You can use this package to install the same in your org https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000M3iZ