Skip to main content

Top #5 Things you should know when moving to #LIGHTNING components from Visualforce

Hello New Year,

Those of you who have barely made it to the 1st, congrats. 2016 has been officially branded as the worst bringer of bad news and us, you and me, have survived and entered 2017. So once again congrats on making it here.

Last year, Salesforce shocked everyone by announcing Lightning, a fundamental and drastic change to the very core of salesforce delivery. The message was simple- this was a major transition in the IT services and if they have not already, all the customers would want their CRM on portal devices. When Lightning was announced, it was like relocating the passengers from a completely full Boeing 404, sturdy durable and slow to the superfast Mig 41 that could deliver fast, break the sound barrier and was efficient- only this was mid-air.

This was a paradigm shift, however, you may want to deny it, and it was fundamentally necessary. But like it or no, the shift happened. And suddenly there was a lot of material out there and every other product that was launched henceforth was labeled Lightning. The good old Visualforce developer that I am, stood behind the crowd in anticipation of what was happening. There were talks, there were webinars, there was stuff happening- and all at lightning speed.

Therefore, it took a while to sort through the noise, cut to the very basics and understand how Lightning works. That effort is now presented in front of you in form of five bullet points that will help you transition successfully to Lightning.

And so we begin, the most fundamental tip that will help you understand Lightning is-

1. Don't Panic

The classic #1 tip given for the average traveler across the galaxy comes in handy when we begin to understand Lightning. There is a lot of material out there for understanding lightning, ready-made components to be used in your code. Start small. If you are familiar with JavaScript you are already there. If not, start now.
Let me repeat this for you, JavaScript is the first step in your transition to Lightning. The golden rule to learning a new language is to write the "hello world" code. A simple code that will get the hang of things. Lightning follows the pattern of any Javascript-based programming language, like AngularJS. Familiarity with one is an added advantage, if not, start learning. Once you get a hang of things, it is really fun to work with.

One way to ease into lightning is to create a basic app fit for your purpose. The Salesforce trailhead gives you a good start into the same.

2. Adopt M-VC

We are programmed to think in an MVC model of programming. We write an apex controller that contains the business logic and queries, the Visualforce page that displays the data. 
A Lightning Component uses the same concept of MVC but here the business logic and display view are written together, while the controller is only used to fetch data. This is the pattern followed by a lightning component. If you have been working on Visualforce/Apex Controllers for a while, it will feel odd initially but once you get a hang of it, building a Lightning component is the best thing you will every do.

3. Write Components inside Pages

With Visualforce, we have practiced hard to write pages for our solutions. We over-use the PageReference apex code to navigate users through the Visualforce wizards. Lightning brings with the most important aspect missing in visualforce pages, it brings the inheritance to the table.
Think of this as writing only Visualforce components instead of Pages. You can further inherit that component into another specializes component for specific use.

4. Everything is in the name

One of the early mistakes I made was not naming the components in the log. If you have a large number of components on the same page and all of them are interacting at the same time, debugging them becomes the stuff of nightmares if you do not name them properly. Create a name attribute to the component that you create and then use this name in the log messages that are generated in the code. You will thank me later for this tip.

5. Javascript is Case Sensitive

A moment of pause to all those who wasted an entire day to realize the problem was onClick. Yes, Javascript is case sensitive. Therefore, if you have a habit of using CamelCase or Camelcase, make sure you maintain consistency. This stuff of nightmare pops up at an unsuspecting time, have faced it many times when trying to access the obj.fieldname but it should be Obj.Fieldname

Some resources that will help you ease into Javascript and further into Lightning:

JS the Right Way

Egghead.io

Trailhead (Duh uh)!

All the best and as always May the Force Be With you!

Comments

Popular Post

The unofficial guide to become a Certified Salesforce Administrator (ADM 201)

In my attempt at maximum certifications in 60 days, I completed Salesforce Certified Administrator exam on February 11th 2013 So you have decided to ramp up your career and take certifications in your hand. Good choice. It is also likely that this is the first time you have heard of Salesforce, certification and since your company has a vision of you completing the certification you have decided to do it. At this stage it is likely that, You have done extensive googling. You have received countless brain-dumps. And you have received plenty of advise from different types of users which ranges from Admin certification is easier than making coffee to Admin certification is tougher than building a rocket-ship to fly off to the moon. The purpose of this guide is to give you a clear understanding of what to expect when you are expected to become Certified Salesforce Administrator. To bring sense to all the things you have seen so far and to clearly explain what to do and what

Some PDF tricks on Visualforce: Landscape, A4, page number and more

The beauty of Visualforce is simplicity. Remember the shock you received when you were told the entire page renders as PDF if you just add renderAs=PDF to the Page tag. For those who thought I spoke alien language right now, here is the trick, to render a page as PDF, we add a simple attribute to the <apex: page> tag <apex: page renderAs='pdf'> This will render the entire page as PDF. Now, say we need to add some extra features to the PDF. Like a page number in the footer or we need to render the page in landscape mode. Faced with this problem, I put on my Indiana Jones hat and went hunting for it in the vast hay-sack of the internet (read: googled extensively). Imagine my happiness when i found a big big page with many big big examples to solve the problem. The document I am referring to is from W3C, paged Box media . Long story short, I now possess the ultimate secret of rendering the page in any format I want. So here are few tricks I learned from the p

The Basics of writing a Apex Trigger

One of the most important and common asked question on Forums and everywhere is how do I write a trigger. Coding in Apex Trigger is like going to a dentist for a root canal, you keep dreading the moment until you realize it is actually not going to hurt you. If you plan to write an Apex Trigger this quick guide will help you doing so. The first and foremost rule in writing a trigger is to remember the oldest suggestion given to the most comprehensive Hitchhikers Guide to Galaxy, ' Don't Panic. ' Writing a trigger is not a rocket science, in-fact we should thank the team at Salesforce and ForceDotCom for making everything so simple, that anyone can do it. Enough of talk, lets code. So you want to write a trigger. Let us have a glimpse of what we are going to build. The problem statement is as follows Problem:  When the User is entering the Opportunity, check for the Opportunity Amount. If the Opportunity Amount is greater than 50,000. Mark the Parent Account as