Saturday 29 October 2016

Lightning Components - New Tab, New You

Lightning Components - New Tab, New You



This is something I’ve been meaning to blog about for a while now, but things like Dreamforce, preparing for Dreamforce and the Winter 17 release kept getting in the way. I didn’t get as far as setting up a nice example, due to the sheer volume of code involved, so I haven’t been back and tried it out recently. Therefore it’s possible that you’ll never have the same experience I did, but as it’s not exactly onerous it seemed worth putting it out there anyway. Your mileage may vary.

Signature move

While building out the MVP for our BrightMedia Lightning booking page to demonstrate at Dreamforce, I needed to change the signature of one of my Apex controller methods, so to get a simple example from something like:

public static Account GetAccount(String idStr)


public static Account GetAccount(String idStr, String name)

and changed the parameters that the Lightning Component passed on the action from:

var params={idStr:'0018000001QtQVA', name:'Blog Post Account'};

That went well!

Once I’d made the various changes and saved all the artefacts, I refreshed the page and starting seeing some unexpected behaviour. The name parameter came through as null regardless of what I set it to. Debug statements in the lightning component showed that the name had a value (it wasn’t a hardcoded string unlike the example above!), but some time after I added it to the action it went bad. Making it a hardcoded string didn’t help, nor did juking around the other parameters. I even tried adding more parameters that definitely didn’t exist server side, but nothing helped.

After a some time and about and thousand debug statements later, I found that while I might be adding the new parameter to my params object, when that was sent to the server it had disappeared, hence the server always reported null.

Cache is king

I then tried what I should have as soon as this manifested itself, the browser equivalent of turning it off and on again. I closed the browser tab and opened a new one. Lo and behold everything worked as expected. We all know that the lightning framework aggressively caches on the front end to improve performance, and it looks like the client retained a metadata view of the server side signature after I changed it.

Now I need to stress that for once I’m not complaining about the behaviour of the framework! This is exactly the kind of thing that I’d expect when caching metadata. It’s not always possible to check everything in a cache is still valid - you quickly start to lose the benefit if you go back and check the source on every request. 

The key takeaway here is that when your application involves caching and you change something which doesn’t work as you expected, open a new tab (or window), or even a new browser. It only takes a few seconds and will save time and heartache in the long run.

Related posts


Friday 14 October 2016

Visualforce Development Cookbook Second Edition

Visualforce Development Cookbook Second Edition



As regular readers of this blog will know, I wrote a book three years ago - the Visualforce Development Cookbook - and I really haven't stopped banging on about it since. Well things just got worse as I finished the second edition in ?September? and I'm obviously keen to shift as many copies as possible!

What’s a Second Edition?

A second edition isn't a new book. Instead it's an iteration on the previous version, minus content that is no longer relevant and including new features, so the first job is to identify what should be cut and what should be added.

One of the nice things about working on Salesforceis that over time new features are added that remove the need for custom code, so I was able to chop a few recipes out that are now handled natively by the platform. The next job is to update all existing code to the latest API version - something that typically happens several times as Salesforce produces releases faster than I can write a book (even a second edition!). 

Then its back to the writing - for existing recipes making sure that the text is still appropriate and creating new recipes from scratch. This was pretty compressed this time around, as Packt proposed a pretty aggressive timescale to complete before Dreamforce which I was more than happy to sign up to, as I knew that would take up all of my time through to mid-October. I wouldn't recommend this if you don't have some vacation time you can dedicate to writing though, as it would have been pretty tough to complete with only evenings and weekends available.

What’s changed?

The main changes in the second edition are:

  • The chapter on sites has been reworked to use the Salesforce Lightning Design System
  • The chapter on jQueryMobile has been replaced with Salesforce1 recipes.
  • A new chapter on Troubleshooting has been added, covering debugging, managing the view state and advice on avoiding common problems.
  • All the retained recipes have been revised as appropriate.

You want me to buy it again?

Now I’m not like the music industry that expects you to buy the same  music every time they think up a different format, and I can understand that for someone who already purchased the first edition, this might not represent enough of a change to justify buying the second edition (although it was for Fabrice Cathala, who is clearly going for the full set - thanks Fabrice!).

I raised this with the publishers and they gave me a couple of discount codes to use, both valid until 17th October, which you can use on the Packt website:

  • Use code VISDSE50 for 50% off the Ebook
  • Use code VISDSE15 for 15% off the print book

Note that you don't need to have purchased the first edition to use these codes, you can simply use them to scoop up a bargain.

Show me the code!

For those who just need the code and no explanation, its available free of charge on github at:

A word of advice though - best not come to me asking for help around adapting the recipes or producing unit tests if you've decided not to purchase the book - that would be asking me to cannibalize my own sales!

Related Posts