Lightning is to Visualforce what .NET was to Visual Basic

When I began my programming career, Visual Basic (version 3.0) was just emerging as a popular alternative for creating Windows-based applications. Ironically, it was a component-based approach to development that brought forth an army of programmers developing third-party components. Programmers could quickly spin up applications by simply dragging and dropping components onto a form design surface and then wiring everything together with events.

Visual Basic grew in popularity and for a few wonderful years, it was the hot new kid on the block. It brought about a sort of programming renaissance and lowered the barrier to entry for many up and coming developers.

Of course, the reign of Visual Basic was not meant to last. No programming language (or platform for that matter) stays golden forever. In 2002, Microsoft launched the object-oriented successor to Visual Basic called VB.NET. I can remember being so excited when it was released and I dove head first into learning all about the new Framework.

I have a confession to make. In all my excitement over the introduction of the .NET Framework, I hurriedly convinced one of my clients to let me rewrite one of his VB applications using VB.NET. Unfortunately, I made a mistake that many developers at that time did. I assumed that rewriting an application like this would be a simple conversion process. That I would just go in and simply swap one set of code for another and magically everything would work wonderfully.

That did not happen. In fact, the application I rewrote started to fall down in production almost immediately. It experienced huge performance problems. In short, it was a disaster. I had actually taken something that was working quite well and turned it into soup.

The problem was that VB and VB.NET were so fundamentally different. Design patterns that worked well in VB, failed miserably in VB.NET.

What I should have done was to start slowly.  Rather than try to convert an existing VB application to using the new .NET Framework, I should have looked at what I needed to do to make the .NET application perform well from the very beginning. I should have learned about best practices and really understood how different the new object-oriented approach to application design would be.

Eventually, I did do all those things, and also switched to using C# (which is much better imho), but only after I messed up my poor clients original VB application. Live and learn, I say. No one is perfect and we all make mistakes. The trick is to learn from them.

I feel like I have learned from mine. But the funny thing is that I can see a familiar pattern emerging now in the world of Salesforce development. I can see how the introduction of the Lightning framework will bring about some of the same challenges for Salesforce developers transitioning from Visualforce as there was for Microsoft developers transitioning from VB to .NET.

VBToLightningSmaller

Some VB developers transitioning to .NET were never able to make the transition successfully and their careers suffered as a result. I imagine this might happen in the Salesforce world too and there will be Visualforce developers that stay Visualforce developers.

Of course, Visualforce is not going away anytime soon. But, anyone that believes it will not go away eventually is just kidding themselves. Salesforce is firmly committed to Lightning and it is no doubt the future of Salesforce development.

So, what should you do if you are a Salesforce developer that knows a lot about Visualforce?

You should embrace the new Lightning development framework and seek to understand how it differs from traditional Visualforce development. It really is like comparing apples and oranges. Begin by checking out this excellent Trail called Applying Visualforce Skills to Lightning. It helps to warn you about some of potential pitfalls you may encounter.

Just like with VB and .NET, design patterns that worked well in Visualforce, will fail in the world of Lightning. You could easily make an application perform worse if you just attempt to swap one set of code for another.

And so this is a good time for me to tell you about a new course I just started to design for Pluralsight. It will be titled Lightning Component Development Best Practices and I hope to release it before the end of the year.

In the meantime, you can also check out my latest course on Pluralsight titled,  Customizing Salesforce with Lightning Components. I have an entire module dedicated to Working with Lightning Data Service and using Base Lightning Components, which are definitely best practices Lightning developers should be using now.

And stay tuned because I will be covering many best practice topics (such as this one about Conditional Rendering in Lightning) on this blog in the months to come.

 

Top 5 Lightning Tips for Visualforce Devs

#1- Transition does not have to be all or nothing

For Visualforce Developers, when it comes to transitioning to Lightning development, it does not have to be an all or nothing deal. Very few development shops/companies will go from doing all Visualforce development to doing all Lightning development overnight. That is just not realistic, nor a good idea, in my opinion.

The introduction of Lightning Out offered a lot of options for Visualforce developers wanting to slowly transition to Lightning. If you want to learn what options are available in terms of a transition plan, I suggest checking out this post and blog series by Salesforce Architect, Mike Topalovich. Mike does an excellent job, not only of giving a lot of background, but of detailing 5 specific migration paths that you will want to consider.

#2 – Watch your Casing

JavaScript is Case sensitive!!!

This is so important, I am going to write it again, “JAVASCRIPT IS CASE SENSITIVE”.

If only I had a nickle for every time I ended up discovering that the odd error I was getting in Lightning was actually caused by a casing error of mine. Seriously, I cannot tell you how many times this has tripped me up. More times than I would probably like to admit.

So anytime you are working with Lightning and you get an error that makes no sense, the first thing you should do is return to your JavaScript code and make sure you did not make a casing error. It really is VERY easy to do. Embarrassingly so.

#3- Security Works Differently

As Visualforce developers, you have been spoiled as far as security is concerned. Visualforce apps operate out of the Force.com domain, which is not shared with Salesforce code. But, Lightning apps and components run in a special domain that is shared with Salesforce-authored Lightning code.

This means that the security for Lightning components are subject to a Content Security Policy (CSP). The rules surrounding what is and what is not allowed with these components will just tighten as time goes on. Go here to learn more about all the concerns regarding Lightning Security.

One important thing that you need to know is that any of your AuraEnabled Apex classes must do an explicit check for CRUD and FLS permissions. This was handled automatically for you in Visualforce pages, but in Lightning, unless you are using the new Lightning Data Service, you will need to do this check manually. You can do so using the isAccessible(), isCreateable(), isDeleteable(), and isUpdateable() methods. You can learn more about how this is done here.

#4 – Install and Use the Lightning Inspector

For Chrome users, there is an excellent plug-in called Lightning Inspector that every Lightning developer should check out. One of the most useful features it offers is a component tree tab, which shows you how the Lightning Framework sees your component. You can use this as a tool not only for debugging components, but learning more about what some of the built-in ones are capable of.

#5 – Check out newest components/features added

The Lightning Framework has been out for a while now (over 2 years actually) and in that time there have been many new releases and lots of new features added. Building Lightning components today is not the same as it was when you may have run through a tutorial or article a year or two ago. If it has been a while since you took a look at what features and components are available, it is time to take another look.

In the last release (Winter 17) many new features were added such as the Lightning Data Service, which you can kind of think of as the equivalent of a Standard Controller for a Visualforce page. Currently this feature is still in developer preview, but using it allows you to eliminate the need for Apex code and also those manual security checks that I mentioned earlier.

I strongly believe that component-based development, such as what you do with the Lightning Framework is the future of web and device-based development. If you have not already dipped your toes in Lightning Development, it is not too late. Things are just getting really good for this modern development platform.

Free Videos from Improving Visualforce Performance Online Course

I just found out I can embed videos from my course for Lynda.com about Improving Visualforce Performance. So, I thought I would do a post and embed the free videos for that course.
https://www.lynda.com/player/embed/428848?fs=3&w=560&h=315&ps=paused&utm_medium=referral&utm_source=embed+video&utm_campaign=ldc-website&utm_content=vid-428848

https://www.lynda.com/player/embed/428871?fs=3&w=560&h=315&ps=paused&utm_medium=referral&utm_source=embed+video&utm_campaign=ldc-website&utm_content=vid-428871

Improving Visualforce Performance – New Online Course Released

Improving Visualforce Perfomance

I am proud to announce that yesterday my online course for lynda.com, “Improving Visualforce Performance” was released. The course is a little over 2 hours long and it focuses on what you need to know to get the most out of your Visualforce performance. It is not a beginning level course (like the first one I did about Developing for Visualforce).

I based the course on a post I did over a year ago called, the “Top 5 Tips for Improving Visualforce Pages“. That post has been the most popular post on this blog for sometime, so I knew this was a good topic.

The course goes into great detail (with examples) of all the tips I covered in that original post. I spent a lot of time developing the examples and scripts for this course and I have to admit I am pretty proud of it. The 5 tips it covers include:

  1. Reducing or Eliminating View State
  2. Evaluating SOQL for Efficiency
  3. Reducing use of Action Tags
  4. Taking Advantage of the StandardSetController
  5. Incorporating Best Practices with JavaScript, HTML, CSS and Images

If you are interested, lynda.com offers a free 10 day trial that you can access here. And until Monday, August 24th, they are offering 30% off the first billing for monthly and annual subscription plans.

I would love to know what you think of the course and what recommendations you have for future course as I plan to be doing more of them.

Developing with Visualforce Course just went Live!!!

The Visualforce course I designed for Lynda.com, Developing with Visualforce just went live. You can access it here and even if you are not a member, you can view 4 videos for free.  DevlopingWithVisuaforce

I am pretty proud of the course. I spent a lot of time trying to think through the best way to teach this stuff to beginners. I hope that I succeeded in some small way. I would love to know what you think, good or bad. I don’t mind getting bad feedback because it helps me to get better.

This is just the beginning too. I plan on doing a whole series of courses. This one was an introductory course, so keep that in mind if you are already very familiar with Visualforce. I stressed using declarative solutions and use of standard controllers whenever possible. I really do believe in the KISS (Keep it Simple Stupid) methodology.

Check out one of the free videos Lynda.com makes available:

http://www.lynda.com/player/embed/197238?fs=3&tr=utm_medium=ldc-partner;utm_source=SSPRC;utm_content=11889;utm_campaign=CD16309;aid=CD16309;bid=11889&w=560&h=315;subID5=197238&ps=paused

Oh, and this is the info on the course:

Course Description:
Start developing custom interfaces for the Force.com platform (including Salesforce) using Visualforce. Sara Morgan walks you through the basics of Visualforce, explores its MVC backbone, issues instructions for downloading a free developer edition of the software, and helps you decide if Visualforce is right for your organization. She then explores how to build pages out of common components; enhance pages with tabs, controllers, and extensions; and use the Developer Console to perform more advanced operations—such as editing multiple records, configuring error handling, and unit testing your code. Along the way, you’ll encounter a series of coding challenges that let you practice and expand your Visualforce coding skills.

Topics Include:
What is Visualforce?
Registering for an account
Building a Visualforce page
Building a tabbed page
Configuring permissions
Using standard list controllers and custom controllers
Exploring unit testing

Duration:
3h 4m

 

Considerations when using Javascript in Visualforce

As part of my research for the new Lynda.com course I am doing on Visualforce, I have been going through posts on the Salesforce forums. I ran across this one in which the poster was asking what was the best way to select multiple checkboxes on a Visualforce page when a “Check All” checkbox was selected.

The best answer that was chosen was a recommendation by someone to use the ActionSupport component. The accepted responder even provided sample code. While the response was technically correct, I did not think it was the best solution. The reason I say this is because if you execute the sample code provided, you will note that there is a significant delay between the time you select the “Check All” checkbox and the time the other checkboxes are selected.

What causes the delay?

The ActionSupport component, which adds AJAX support to another component, allows that component to be refreshed asynchronously. While you might first think, “Asynchronous, that executes on the client and that is good and fast, right?”, that is not really the case. You see, when you use ActionSupport, or ActionFunction, or any of the action tags, you are essentially invoking server-side logic that is contained in your controller. This means that the AJAX request includes the pages view state and this can affect performance, as it did in the very simple example from this post.

So why use these controls?

Well, they are much easier to use than some of the other alternatives (which you can read more about here) and typically result in less code. But, if you are a good software developer, then you should not just blindly accept the path of least resistance. The other alternatives (namely Visualforce Remoting) will certainly perform better, but then they do require more code to be written. There is always a trade off, you see.

So, what is the best solution for this problem?

Well, I know you are going to be annoyed when I say this, but the answer is, “it depends”.

You could say the best alternative is one that was suggested by another responder on this post. That responders suggestion to use client-side JSJavascript (such as is provided in this post) was not accepted as the solution, but if you execute the code provided it does execute extremely fast. The difference in performance between the two suggestions is day and night (IMHO). But, this requires you to write and maintain the extra Javascript code.

If you are just sold on the whole, “it is better to use the built-in Action components provided by Visualforce because they simplify the code”, then you might want to consider adding an ActionStatus component right below the ActionSupport component. This is used to provide a message to the user telling them when the process starts and ends. That would prevent the user from just sitting there dumfounded for 1 – 3 seconds while the code was executing.

You might also want to consider using some of the other Javascript alternatives suggested in this excellent Developer Relations post on Using Javascript with Force.com.

You see, it really all depends on what you are trying to accomplish and what skills you already have. If you are blessed to have the time to consider other options, then I suggest you do so. There are often many ways to accomplish the same thing and rarely is one way always the best way.

 

Approved as a new Lynda.com Author

lynda_logo1k-d_72x72I just got word that I have been approved to be a new Lynda.com author! They want me to design a series of courses on Salesforce development. They currently have none, so this is very exciting. One of the things I really like about Lynda.com is their commitment to high-quality productions. They are leaders in the area of online video training.

The first course will likely be very introductory (such as “Up and Running with Visualforce Development”).  If you have suggestions for areas you think I should cover, I would love to hear from you. Feel free to comment to this post or to send me a message directly though my contact form.

I will be sure and announce when the course is approved and of course, when it is released. Until then, please send me your thoughts.

Add Audio/Video Conferencing to Any Visualforce Page with GoInstant

GoInstantlogo-174x174It is very likely you missed the announcement less than two years ago about Salesforce acquiring a Canadian-based company named GoInstant. It is also likely that even if you attended Dreamforce in late 2013, you missed a very informative session titled, “Build Real-time Multi-User Apps with Visualforce, GoInstant and AngularJS“.

From what I can tell, not much fuss has been made so far about the Backend-as-a-Service provider that was founded in 2010 and acquired by Salesforce in 2012. I imagine that is mostly because up until a few weeks ago, there was not much you could do with GoInstant, other than add chatting capabilities (Hello, Salesforce already has Chatter).  But, with the recent integration with WebRTC (or Web Real-Time Communication), we may be seeing a lot more possibilities popping up.

GoInstant recently released a WebRTC-based widget that lets you EASILY add Audio/Video conferencing capabilities to any Visualforce page. No back-end servers required! And, it is completely free for the first 1000 monthly active users!!!

GoInstant handles all the complexities involved with offering this type of functionality. They handle security, data synchronization and storage, and even scalability. The WebRTC widget specifically lets you initiate, pause, and mute a video stream, all with a single click. And no need for the client to download anything (YEAH). It’s kind of like being able to offer the ease and power of Skype within a secure Salesforce connection.

webrtc-plus-goinstantI can see this type of functionality being really useful for customer support situations, but I can also see it being heavily used in the Enterprise for internal communications. Now, even small to medium companies can offer the type of audio/video chatting once only available to the really BIG enterprises. In fact, I imagine, even the big Enterprises will want to consider dumping their expensive and hard to maintain Unified Communications systems for something like this.

One Gotcha to consider is that currently, WebRTC is only supported in the latest versions of Firefox and Chrome (but I expect the list of supported browsers to be growing very soon). Another thing to consider is that there has still been no final decision made about what standard video codec will be used. (but again, I am sure this will be resolved soon enough).

If you want to see how this works right away, check out this demo created by the clever folks at GoInstant. And, if you want to start playing with this type of functionality in your developer org, I would recommend you check out this GREAT post on Developer Force about how to use the widget in a Visualforce page.

Training Review: Force.com Training on Pluralsight.com

Anyone that reads my blog knows that I am big fan (and regular subscriber) of the Pluralsight training videos. I cannot imagine staying up to date as a programmer without them. At this time, there are only a limited number of courses that cover the Force.com platform (8 to be exact), but I expect new titles will be added very soon. logo-v4

I really think that viewing these courses can be beneficial to anyone studying for the basic or advanced developer certification, or just people working with the Salesforce.com platform in general. These courses can also be valuable to developers (of any platform) that want to determine whether learning more about the Force.com platform is beneficial to them.

Pluralsight offers a free trial that allows you to view 10 days and up to 200 minutes of training. That would allow you to view for free at least one, but maybe two of the courses I describe in this post. Below, I will summarize which courses you should view, depending on where you are coming from and what you are trying to achieve.

First of all, if you only have time to watch one of these courses, I would watch this one:

Force.com Platform: The Big Picture by Don Robins – This is a high-level course that would be very useful for someone brand new to the platform. It is short (1 hours and 24 minutes) and would also be of great interest to experienced developers that have not worked with the platform for long. Robins includes a lot of history about Salesforce and does an excellent job of describing the “Perspective Shift” that is necessary for developers that want to be successful on the platform.

If you are studying for the First-Level Salesforce Developer Exam, I recommend viewing the following course:

Force.com For Developers by Richard Seroter – This is the longest course in the series (5 hours and 47 minutes), but it is also the most thorough. It provides a good overview of the entire platform in a very clear and easy to understand way. Seroter covers many topics that are covered on the 401 Dev exams, such as Reports, Workflows and Approval Processes. He also covers topics on the 501 Advanced Developer Exams, so this course would be good for people studying for that exam as well.

If you are studying for the Second-Level Salesforce Advanced Developer Exam, I recommend viewing the following courses:

Force.com Design Patterns – Part 1 by Adam Purkiss – This course is definitely not for beginners or anyone new to the platform. Purkiss talks about advanced topics such as the use of wrapper classes to get around some of the inherent limitations of SOQL. Some of the code walk-throughs were unpolished and appeared to have not been practiced in advance, but the beginning of each section was very good. My favorite section was the one on Trigger Design Patterns.

Force.com Design Patterns – Part 2 by Adam Purkiss – This course has three distinct segments and I can see the first two (Test Design Patterns and VisualForce Architecture) being especially valuable to anyone pursuing the Advanced Developer Certification. I actually enjoyed this course more than the preceding Part 1, because the examples were more general and the author did not have to waste a lot of time describing how the sample application worked. Purkiss includes many best practices that if you follow will ensure that your code stands the test of time. I really enjoyed the section on how to use Knockout.js to do JavaScript Remoting to create an HTML page that saved custom settings directly to Apex.

Introduction to Visualforce by Matt Lacey – This was my least favorite course, mostly because the speaker had a heavy accent that was hard to understand. He also rushed through the content and the general audio quality of the video was bad. However, the course did provide useful content that would be relevant to anyone studying for the Advanced Developer exam.

If you are an Experienced Software Developer that wants to understand more about the Force.com platform, I recommend viewing the following courses:

Force.com for .NET Developers by Dan Appleman – This course does a very good job of describing the Force.com fundamentals in way that makes sense to .NET developers specifically. Appleman is an experienced author who spent many years creating content for the .NET community, but a few years ago he switched (almost primarily) to working with the Force.com platform. Like myself, Appleman does not dismiss the .NET platform and certainly sees it as still viable, but he also can see the alluring reasons to understand the Force.com platform as well.

Force.com and Apex Fundamentals for Developers by Dan Appleman – Unlike the last course that was specifically designed for .NET developers, this course was designed for developers coming from any platform. It is not a course for people new to programming, but attempts to give experienced software developers a head start to writing “GOOD” code on the Force.com platform. Appleman will tell you about best practices and describe real-world scenarios that only come from hard-earned experience. Most importantly, he covers why design patterns used in other languages do not always apply in Force.com. He focuses on the 4 most important concepts (Execution Context, Use of Static Variables, Limits and Bulk Patterns) that you need to know to start working safely and efficiently in Force.com.

Patterns of Cloud Integration by Richard Seroter – This is NOT a course specifically about Force.com and instead focuses on many technologies that can be used to accomplish integration with cloud applications (on any platform, Force.com included). This course would be of great interest to any technical architects that need to understand to complexities involved with integrating cloud-based applications. Seroter is no doubt an expert in this field and he covers a variety of tools and platforms (such as Biz Talk Server, Windows Azure Service Bus, Mule Cloud Hub and custom code using .NET, node.js, Java, etc) used to integrate Ground to Cloud, Cloud to Cloud, or Cloud to Ground scenarios.

Book Review: Visualforce Development Cookbook

Not a book for beginners, but GREAT for seasoned Apex developers

I recently had the honor of reviewing the recently published, Visualforce Development Cookbook. The code recipes are great and could really go far in demonstrating the potential of the platform. It is obvious that the author, Keir Bowden has implemented many, if not all of these recipes in real-world scenarios. However, I think this is a dangerous book for developers new to the Force.com platform. In fact, I would not recommend it to anyone who has not worked with the platform for at least one year.

While step by step instructions are provided, along with occasional notes about real-world considerations that should be made, the author does not go into detail about these considerations. For example, on page 36, the author advises readers to use a Utility class to handle creating the data, but does not go into how to actually do this.

Also, the author only provides test code for one of the recipes in the first chapter and then never mentions testing again. Anyone that has worked with the platform for a while knows that writing test code can sometimes take longer and be more difficult than writing the actual code. I could see someone new to the platform using this book to create many changes in their development org and get everyone excited about using the stuff and then never be able to get all the required unit test code together in order to deploy.

The sample code that was provided was easy to download and well organized. It was also formatted properly so that you could cut and paste it straight into your development org. Very little sample code is included in the actual book, which I think helps to ensure that the book stays up to date. As long as the publisher and author continue to update the sample code with each new Salesforce release, the code should stay viable as the platform inevitably changes.

I REALLY liked the chapters on JavaScript, Force.com Sites and Mobile Development and cannot wait to try out some of the recipes included for my clients. My favorite part of the whole book was the fact that the author utilized the Google Hosted Libraries Content Delivery Network rather than static resources for the jQuery code. This was a very smart move and helps to ensure that the code stays viable in the future and also makes use of the latest industry standards.

Some of my favorite Javascript recipes included the tooltips (which featured a slick slidedown effect), the collapsible list elements and the scrolling news ticker. This chapter really demonstrated to me the power of Visualforce and how you can use it to make some powerful and dynamic pages that are unique to your brand.

I really appreciated the final chapter on jQuery Mobile. In fact, if you read only one chapter in this book, read this one. As the author explains, the book is about Visualforce and not mobile development, so it focuses on using HTML5 and the jQuery Mobile Framework to provide the interface code. My favorite recipe in this chapter was the one on navigation and transitions. The author includes transition examples that pop, flip, turn, flow and slide the user from one page to the next. Sweet!!! I will warn you that the code did not display well on my iPhone, but I plan on looking into this further and if I find out the reason why, I will do a separate post about this.

I did find a few inevitable errors in the book as I worked through the code recipes, but the errors were minor and I got past most of them easily. I will report the ones I found to the publisher as errata.

In short, this is an invaluable resource for seasoned Force.com developers, but should be approached with caution for newbies. Force.com is a powerful platform. Much more powerful than most people give it credit for. While this book does include recipes that clearly demonstrate that power, I think experience is needed to help the reader apply the knowledge from this book in the best way possible.