https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shAutoloader.js

Sunday, 25 May 2014

Salesforce1 World Tour

The Salesforce1 World Tour reached London on 22nd May 2014.  In a change of format from previous Salesforce events, the Expo and Dev Zone was open from 8:15 until the keynote started at 10:30.  As BrightGen, were a Platinum Sponsor, this meant our stand had to be show ready by 8am.  The stars had aligned for us in terms of workloads, which allowed us to bring a fair few staff with us, including a few new joiners who had never been to a show before.  

We had a high level of interest in our offerings, so I spent most of the day on our stand aside from my Dev Zone talk at 2:30. Every year the Dev Zone gets bigger and better and this year was no different - standing room only for all of the talks and a very attentive audience.  My talk was on Responsive Design with Visualforce Pages and the slide deck is available below:

For my talk I created a simple blog site, containing a home and links page.  You can access the site at : 

http://bobbuzz.me.uk/SF1RD

and if you’d like to see the code behind it, that is available on Github at:

http://bobbuzz.me.uk/SF1GH

The Github repository has a link to an unmanaged package if you’d like to install the code into your own developer edition to play around with it.

Sunday, 18 May 2014

London SFDG May Meetup

Like our April meetup, the May event took place a couple of weeks early as once again we had a special guest - Salesforce Developer Evangelist Christophe Coenraets was in town and gave a talk on Angular, Ionic and Heroku Connect.  We also had a change of venue, as the event was kindly hosted by Appirio at their West End offices.

Some I found very interesting was that Christophe was running his presentation from Salesforce1 application using his Keypoint1 application:

Ccsfdg

After some slides on mobile application architecture, Christophe then live-built a simple Ionic application and walked us through how to integrate that presentation layer with AngularJS. Finally, he showed us Heroku Connect (this first time I’ve seen this, although I’ve read a lot about it) and a customer loyalty application built on all of these technologies.

After a break for beer and pizza, of which there was plenty:

Pizzasfdg

Next we had Florien Hoehn, one of our meetup members, speak about the new Remote Objects functionality available in Developer Preview in the Spring 14 release of Salesforce.

The next meetup is will be announced on the London Salesforce Develoeprs Meetup Group - if you are a Salesforce developer based in or around London, make sure to sign up as a member.

Saturday, 10 May 2014

Transient List Command Button Woes

Doug Grimwade, one of our tech leads at BrightGen, hit a strange problem this week around command buttons (or links) not executing the action method they were associated with, but simply refreshing the page.  Dwindling the page and controller down to their essentials we were left with:

Controller:

public with sharing class RepeatCtrl
{
  public transient List<Account> accounts {get; set;}
  public Integer counter {get; set;}
	
  public RepeatCtrl()
  {
    counter=3;
    setupAccounts();
  }

  private void setupAccounts()
  {
    accounts=[select id, Name from Account order by CreatedDate asc limit :counter];
  }
	
  public void incCounter()
  {
    System.debug('### Inc Counter Called');
    counter++;
    setupAccounts();
  }
}

Page:

<apex:page controller="RepeatCtrl">
  <apex:form >
    <apex:pageBlock title="Accounts">
      <apex:pageblocktable value="{!accounts}" var="acc">
        <apex:column value="{!acc.Name}" />
        <apex:column headerValue="Action">
          <apex:commandButton value="Inc Counter" action="{!incCounter}" />
        </apex:column>
      </apex:pageblocktable>
  
      <br/><apex:outputText value="Counter value = {!counter}" />
    </apex:pageBlock>
  </apex:form>
</apex:page>

 The basic premise of this page (remember this is reduced to reproduce the problem) is to display a list of accounts, with the size of the list dictated by the counter property.  Pressing any of the buttons should increment the counter and refresh the list with an additional element.  

Opening the page displayed the initial list as expected:

Screen Shot 2014 05 10 at 15 35 14

However, clicking a button didn’t work as expected:

Screen Shot 2014 05 10 at 15 36 21

the list has disappeared and the counter value hasn’t incremented.  Investigations in the log file showed that the action method wasn’t being called, as the debug information didn’t appear.  

Moving the post back to an action function, invoked by a click handler on the command button fixed things:

<apex:actionFunction action="{!incCounter}" name="incCounter"/>
...
<apex:commandButton value="Inc Counter" action="{!incCounter}"
        	onclick="incCounter(); return false;"/>

 

As did adding a command button outside the pageblocktable worked correctly - the counter was incremented and the list displayed four elements:

Screen Shot 2014 05 10 at 15 39 38

So it appeared that the issue, for some reason, was that the component carrying out the postback was nested inside the pageblocktable iterator element.  

While I dug around on the Developer Forums for a solution, Doug was trying various tweaks to the code and found the problem - the transient nature of the list of accounts.  Making this list non-transient and storing it in the Visualforce view state fixed the problem: 

public with sharing class RepeatCtrl
{
	public List<Account> accounts {get; set;}

...

Armed with this information I continued googling to see if this was documented behaviour, but this turned up no results.  Remembering that Visualforce is essentially built on JSF, I searched in that direction, and turned up a promising hit:

JSF2 Command Button Not Working

which states:

If command button is nested in a ui:repeat tag, command button or link will not work until the iterating bean/List is in view scope or bigger scope.

...

JSF iteration controls generally maintain a cursor to do their work, and the only way that the cursor can function properly is if the referenced datamodel is in a non-transient scope. For JSF1, that means Session Scope or higher. For JSF2, View Scope or higher.

View Scope in JSF equates to View State in Visualforce, so this matched our scenario.  Even though the command button didn’t use or rely on any element in the list being iterated, that fact that it was inside the iterator meant that the list had to be reconstructed server side before the command button would work correctly.  

A couple of lessons learned here then - transient has some side effects and if you can’t find behaviour documented in Visualforce, its always worth a look at the building blocks of the technology. We were quite pleased that it didn’t take us 6 hours to find the fix, even if we didn’t understand the solution correctly, unlike the poster with the JSF problem. Hopefully this blog will help the next developer to encounter this issue fix it even faster.

One last thing on an unrelated note - the @forcedotcom twitter handle has been replaced with @salesforcedevs 

Sunday, 4 May 2014

Salesforce1 Developer Week London

In case you weren’t aware, Salesforce1 Developer Week took place at the end of April 2014 - in fact it seems to have been more than a week judging by the events on the official blog page.

The London event took place on 30th April, kindly hosted by TQuila at their headquarters in Lindsay Street.  Registrations took a bit of a hit when strike on the underground was announced to coincide with this, but on the day more than 50 people attended - an excellent effort.

After pizza and beers, the evening was kicked off with a presentation on possibilities of the Salesforce1 mobile application, from a configuration and programmatic perspective from myself and Richard Clark, CTO of Make Positive:

S1dwrc

  S1dwkb

 

 

 

 

 

 The attendees then retired to the main "cabin" of the office to crack on with the workbooks, mini-hacks or simply to solve some real-world problems they had been struggling with:

S1dwwork

From time to time the best practice discussions became heated :)

S1dwblows

but we were all friends again after an hour or so of hacking, and it was back to the presentation area to demonstrate what had been built:

S1dwdemo

Something that really stood out for me was the contrast with the Elevate mobile workshop that took place in London in March.  There, a fair amount of time was spent setting up the environment, especially for android development involving the emulator, and most people had to push hard to get through the workbook in a whole day.  This time around, everyone was up and running without incident, and my time as a helper was spent advising how business problems could be solved using the application.

If you were unable to attend a Salesforce1 Developer Week event, you can still try the workbook and hacks yourself using the following links:

Our next event takes place on Wednesday 14th May at the Appirio offices near Bond Street station. Christophe Coenraets, Salesforce Developer Envangelist, will be joining us for a talk on Angular.js and Ionic.  I’ve followed a lot of Christophe’s community activity at both Adobe and Salesforce.com and he’s done some interesting work, so I’m really looking forward to this.  You can signup for this event on the meetup page.