Saturday 30 June 2012

HTML Comments in Visualforce Pages

After seeing the presentation from Wes Nolte at Cloudstock London, I've been playing around with knockout.js in my spare time over the last couple of weeks and am very impressed.  I've been building some apps using JQuery Mobile and an area of concern has been the way that I've been striping HTML through javascript functions in order to update page sections with the latest data - using knockout.js I don't have to worry about this any more as I can bind the data and respond to user interaction via an almost Apex controller-like javascript object.

One of the feature of knockout.js is the ability to iterate an array of data via a foreach.  With HTML containers that naturally contain a repeating body (e.g. TBODY or UL) the data can be bound directly to that element. However, if you have a block of markup that you want to repeat without a container (in my case it was simply a DIV element per entry in the array), you make use of HTML comments to wrap the body.  An example of this is shown below, where there is a single static list item and the rest are generated from an array:

<ul>
<li><strong>Days of week:</strong></li>
 <!-- ko foreach: daysOfWeek -->
 <li>
  <span data-bind="text: $data"></span>
 </li>
 <!-- /ko -->
</ul>

<script type="text/javascript">
function viewModel() {
  var self = this;
  self.daysOfWeek = ko.observableArray([
   'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'
  ]);
};
ko.applyBindings(new viewModel());
</script>

In this case the <!-- ko foreach: daysOfWeek --> comment indicates that everything between it and the <!-- /ko --> end comment should be repeated for each element in the daysOfWeek array of Strings, and the <span> inside each list element should be populated with the array element via the data-bind="text: $data" attribute.  


After saving this markup in my Visualforce page, I viewed the page to be disappointed by the sight of a single list item with the text 'null' in the embedded span.  As I was green to this framework, my initial assumption was that I'd done something wrong.  Observable elements need to be accessed as a function rather than an attribute, so maybe I needed some additional brackets in there?  That just made things worse.  I then added in some debug to output the size of the array in case I'd made a mistake there, and that showed that there were 7 elements as expected.  To check that there wasn't an issue with the javascript file I'd downloaded, I rewrote it to use the UL element as a container and that worked fine.  Some googling showed that nobody else was having this problem, so it was clearly something that I was doing.  After some more head scratching and unsuccessful tweaks a synapse fired and I remembered having a similar issue when attempting to use CSS conditional comments for IE. These comments are interpreted by IE and ignored by all other browsers, so allow specific code or includes to be executed for the IE browser:
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

I couldn't remember the exact issue, but I'd ended up writing a controller that inspected the USER-AGENT header as I couldn't make it work in the page.  Once I'd found the notes it came flooding back - Visualforce removes HTML comments.  Checking the source of my rendered page confirmed this - my bounding comments were nowhere to be seen.  Moving the logic to the controller wasn't an option here, so I started looking for a workaround.

My first thought was to place the comments inside outputtext tags with the escape attribute set to false:

<apex:outputText escape="false" value="< -- ko foreach: daysOfWeek -->" />

While this was successful in outputting an HTML comment, the body was replaced with asterisks, hardly helpful:

<-- ********************** -->

I really don't understand why this happens - either leave the comment alone or remove it. Mangling helps nobody and adds unnecessary characters to the page.

After a bit more experimentation I came up with the following notation:

<apex:outputText value="<" escape="false"/>!-- ko foreach: daysOfWeek --<apex:outputText value=">" escape="false"/>

It looks pretty ugly but does the trick.  By the way, if you are thinking that this could be made more readable using a custom component, I thought the same, but custom components get wrapped in a bonus <span> element, which broke things.

Upon changing my example markup to:

<ul>
<li><strong>Days of week:</strong></li>
 <apex:outputText value="<" escape="false"/>!-- ko foreach: daysOfWeek --<apex:outputText value=">" escape="false"/>
 <li>
  <span data-bind="text: $data"></span>
 </li>
 <apex:outputText value="<" escape="false"/>!-- /ko --<apex:outputText value=">" escape="false"/>
</ul>
<script type="text/javascript">
function viewModel() {
  var self = this;
  self.daysOfWeek = ko.observableArray([
   'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'
  ]);
};
ko.applyBindings(new viewModel());
</script>

Everything started working as expected and my faith in knockout.js was restored.  If you agree that HTML comments should be left in the resulting page, please vote up my idea.



Monday 4 June 2012

Salesforce Certification

In one of my earlier blog posts in April, I set up a mobile application that allowed readers to take a survey on their phone.  At the time I said that I might even take notice of the responses, and I've written this post because I decided I would!  Big thanks to those that tried the app out and gave me feedback.

One area that cropped up a few times was Salesforce certification, and this is also an topic that has garnered a lot of interest when I've blogged or tweeted about it in the past.

Why Get Certified

There are many good reasons to get certified.  A few that I'm aware of are as follows:



  • Enhance your career prospects One of the ways in which Salesforce Cloud Alliance partners are measured is on the number and type of certifications their staff hold, and as the partner level increases through Silver, Gold to Platinum, the number and types of certifications required increases.  For example, Platinum Partners are required to have at least one Technical Architect on staff (which is why I had to complete this exam at pretty short notice at the beginning of the year!).  
    Thus having the appropriate certifications will definitely make you a more interesting candidate and most partners that I am aware of seem to be permanently recruiting these days.  Here at BrightGen,
    we are always interested in the right people.

  • Gain Credibility with Customers In my experience, while this isn't something that customers are particularly aware of initially, it is generally well received when you list your certifications and explain the study and effort that you've had to put in to gain them, and your opinion carries more weight.  Obviously this can vary - for example, one prospect didn't seem to be particularly excited about my extensive list of certifications, but when they handed me their business card, mentioning a PhD and membership of a number of chartered institutes, I began to understand why.

  • Validation Its a great feeling when you see the "Congratulations" message after submitting the exam. Moreover, you have demonstrated the appropriate level of knowledge and ability to earn that certification, which means that you must know something about it!  You can take comfort from that when you find yourself struggling or doubting your decisions.
  • Special Events This is something specific to partners rather than all certified professionals so doesn't apply to everyone.  Events such as Spark the Social Enterprise give excellent opportunities to network with your peers and gain access to key Salesforce experts.  
  • Because its there This was the motivation for me for the advanced admin and advanced developer exams.  Once I'd got those that were required from partnership perspective, I decided that I didn't want to stop until I'd got them all.  As I had the original Consultant certification which was discontinued in March 2012, I heaped additional pressure on myself to get all eight while that was still possible.

Resources

There’s a wealth of information on the internet regarding Salesforce Certification.  As is usually the case with these things, not all of it is useful!  My favourites are:
  • Salesforce.com Certification Facebook Page
    This is where the latest news will break regarding assignment windows and exam status.  They also have regular ‘office hours’ Q&A sessions with their certified experts, which can have really useful information.
  • LinkedIn
    There are a number of useful study and discussion groups on LinkedIn.  The Salesforce.com Certification team also post information and respond to questions, so its well worth following them.
  • Force Certified
    The grandaddy of them all.  Great work by John Coppedge.

Studying

The starting point for me with any exam is the Study Guide.  This gives you details of the purpose and format of the exam, and then a point by point summary of the areas that you will be tested on and how much they count towards the overall mark.  

What happens next really depends on how you like to study - if you find videos the best way, the premier online training catalog has great material, including knowledge check questions throughout to see if any of it is sticking.  If you don’t have access to that, there’s a huge amount on the Salesforce channel on youtube.  

Personally, I’m a big fan of the written word, so I’ll usually head to the online help and go straight to the Printable Tip Sheets and User Guides section.  This is a collection of short documents that take you through setting up and using various aspects of the system.  Its basically the same information as can be found elsewhere in the help, but each document is standalone and takes you through planning, configuration, rollout and day to day use.  I find that reading through these documents while actually setting up and configuring a developer org really helps things stick in my mind.  I also tend to scribble my own highly distilled notes at the same time, then write these up into a short ‘pass notes’ style document that I use to refresh my memory in the run up to the exam.

The Exam

After all the hard work and studying is done, it’s exam time.  I’ve been taking the online proctored versions since they became available, as I much prefer sitting in my own house to travelling to my nearest testing centre in London.  The slight downside to this is that the setup is all my problem.  Clearing everything out of my study and setting the webcam up always takes longer than I expect, so if you are going this route make sure you allow plenty of time.  Also make sure that your webcam and microphone are working well in advance, so that you don’t find yourself rooting through boxes in the attic for your old microphone 10 minutes before the exam is due to start, which is exactly what happened to me the first time!

For most of the exams, the format is similar - a set number of multiple choice questions to be completed in a time limit.  The number of questions, time limit and passing grade differs, but all three increase as you move up the certification food chain.

Below are my tips when taking the exam:
  • Make sure your webcam is set up exactly as required.  I’ve not had any issues with this, but I know people that have and by all accounts it’s pretty annoying and distracting to have the exam freeze and need to call the US.
  • Read the question carefully.  Its really easy to miss the “not”, “doesn’t” or “excluding” and thus end up giving the perfect wrong answer.
  • If you don’t know the correct answer, try to derive it by excluding the wrong answers.  As Sherlock Holmes said: “When you have eliminated the impossible, whatever remains, however improbable, must be the truth.
  • If you don’t know the answer and can’t derive it, mark it for review and move on.  A lot of the time it will come to you when you are thinking about another question.  Very occasionally a later question will be asked in such a way that it will guide you towards the correct answer for an earlier question.
  • If you have access to a pencil and paper, note down how confident you are in the answer.  Based on the passing grade for the exam, it gives a good indication of the pass/fail likelihood.  If you’ve got a high level of confidence in most of the answers, you don’t need to sweat that there are a couple of guesses in there.  Of course the reverse is also true - if they are all guesses its going to be a bumpy ride.
    I give mine a percentage rating:
    • 100% - definitely correct, in my mind anyway
    • 75% - pretty sure it’s correct, but wouldn’t hurt to check later
    • 50% - I’ve narrowed it down to a couple, one of which is definitely the answer
    • 25% - one sounds more plausible than the others
    • 0% - total guess

Share the Love

After you’ve taken the exam, share your experience with the wider community.  Even if you didn’t pass, you may be able to serve as an example for others!

Once you have your certification, you may become the subject matter expert for that area within your company.  Organize some presentations or study group sessions to pass on your knowledge to your colleagues.  This is something I’ve done a fair bit of at BrightGen, and it really works.  Start out with a general heads up about the topic, then capture feedback at the end of each session about what the attendees would like to cover next time and before long you’ll have a team of certified experts and a rich library of collateral.

Write a blog post on your certification journey.  Try to put your personal spin on it, rather than just repeating topic areas from the Study Guide. Was it harder or easier than you thought?  Were there areas that cropped up a lot so you really need to know those in depth? How did you prepare for it, and if you did it again would you try a different approach?

Don’t Game the System

Once you start sharing information, you are likely to start receiving requests to share dumps or sample questions.  Don’t.  You’ve put all that hard work into it, why should someone else get an easy ride?

Don’t try to game the system yourself either.  While having the credential might get through the door for a job, you’ll quickly be found out if you haven’t earned it.   I can’t think of anything worse than being presented to a customer as an expert in the field and then being unmasked as a chancer.  The Salesforce community is also tightly knit, so if you do this the word is likely to spread.

The Sales and Service cloud certifications were withdrawn in April 2012 and have just returned to beta, due to reports of the question and answer set being publicly available.  This is a poster child for the damage that gaming the system can do. Many innocent parties who studied hard for the exam suddenly had their booking cancelled due to a few guilty ones who wanted to cheat their way to success.  In some ways this can be viewed as a backhanded compliment - if the credential wasn’t worth having, people would be trying to cheat their way through, and if it was easy to achieve they wouldn’t need to cheat.


Cloudstock Slide Deck


I had this blog post written a few weeks ago, but then an opportunity to present at Cloudstock came up so it had to go on hold so that I didn't pre-empt my talk. My slide deck from that session is available for download here.