Why Visualforce was awesome
The Lightning difference
With Lightning, Salesforce truly looked at rearchitecting presentation layer from the ground up, beginning with the principle that everyone builds with the same core tools. Lightning delivers on that promise. In developing the classic UI, developers on Salesforce product teams used one set of tools while our customers used Visualforce. With Lightning, we’re all using the same UI framework.
The ECMAScript standard
One of my favorite features is destructuring variable assignment. A simple example could be you want to quickly pull out values from one or more fields in JSON that’s been returned by a server request. Let’s say it was in a variable called
obj that looked like this:
You might do something like this:
But instead you can just do this:
Actually, you don’t even need to settle for the names of the properties inside the JSON object. You can create your own variable names at the same time:
I do need to be clear that as of the time of writing ES6 is not officially supported in Lightning Components. This is particularly important if your users are still on IE11. But there is some advice available as to how and which features to use today. The Lightning Product team is looking at how to move to full ES6 support in Lightning development in the future.
For instance, try the following:
- Open this blog page (or any page) in a Chrome browser.
- Open up Chrome developer tools (CMD-OPT-J on Mac or CTRL-SHIFT-J on Windows).
- Enter the following, hitting
Enterafter each line:
var newDiv = document.createElement("DIV");
document.body.innerHTML = "";
The first two lines create a new
<body> of the current page. Then finally we append the new child node onto the body. At times, I have found it really useful to see how to manipulate the thing I’m working with directly to test out how code I’m working on will work.
Wrapping it up
- Code Playgrounds
- TrailheaDX Sessions
About the author
Peter Chittum is a Developer Evangelist for Salesforce who discovered coding in his late 20’s. Before joining the Developer Evangelism team he was a 13-year long veteran of enterprise software developer and technical training. He has a keen interest in helping developers learn new technologies and “de-scare-ifying” development and developer tools for non-coders. Follow his tweets on @pchittum.