Friday, June 13, 2014

Modals are part of the Visualstrap from very beginning but I never talked much about them. Modals can be really help to enhance the user experience. They can let you do many things without going to and fro between pages.

In Salesforce, we are used to this type of arrangement. For example have a look at the "New" / "Edit" buttons, they will take you to a another page to accomplish the task. It feels a bit clunky.
To make the experience  fluid and fast these pages can be replaced with modals.


Lets say we want a page where
  • See all the cases
  • Create new cases
The page can be extended to close and update the cases as well


The Page & Controller 

The page and controller are pretty simple.

The Catch

  •  Opening Modal : Modal can be opened using JS or html attribute. In this demo we are using JS
    <a class="btn btn-success btn-md" onclick="$('#newCase').modal('show');return false;">New Case</a> 
Closing the Modal Only when insert is success : We cannot just close the Modal when the user presses the Save button because there can be validation errors/required fields missing etc. To control this we are using a controller variable "isSuccess". We are setting it to true only if the transaction was success and based on the variable value we are calling the modal hide on the page.

Controller : This method sets the isSuccess flag to true only when the records is saved successfully.
    public void saveCase(){
            insert caseObj;
            isSuccess = true;
        catch(Exception ex){
            isSuccess = false;

Page : The below section only renders when isSuccess is true ( and lets the page to close only when the save was success )

<apex:outputPanel rendered="{!isSuccess}">

VSModal in action

Below is the live demo of the page, you are welcome to try creating some cases for me :)

Saturday, June 7, 2014

Salesforce has just released RemoteObjects and its really promising. You can now do lot more by just writing a page and without any need of a controller.

RemoteObjects now lets you do DML, Query etc just using the Javascript and to add they are not even counted against the limit. Lets see how can we use the same to create a stateless Pageblock table.


  • Jquery : For DOM Manipulation
  • JSRender : For templating
  • Some styling


Jquery is a very popular DOM manipulation library and if you are into JS you probably don't need any introduction of the same. Jquery in this DEMO does the job of DOM manipulation like picking up templates, changing DOM etc.


JSRender is not so popular templating engine which is successor of JQuery Templates. Lot of things have changed from JQuery Templates and they are now much more easier to use than ever. I have been preferring JSRender because they need very less code and are easier to use and understand.


To give our table a familiar look of PageBlockTable we will have to borrow some styling for Salesforce.

Styling from Salesforce

The Page

The end result

Whats Advantage ?

  • Almost zero viewstate
  • Pretty fast loading time and refresh
  • Suitable for mobiles and large pages