Tuesday 2 August 2016

Discover new opportunities in IT, South Wales style!

August 13th 2016 sees the first ever Surf Force event, held in Aberavon, near Cardiff.

But what is Surf Force?

Surf Force is the brain child of Desynit's very own Shaun Holmes. a once award winning surfer, turned Salesforce expert. Shaun wants to combine his passion for this fun oceanic hobby with opening the doors for new opportunities in the IT sector in Wales, with one of the most innovative and welcoming computer technologies, Salesforce.


Why should you attend this totally free event?

If you wish to, arriving a little earlier will get you a full on breakfast, and a couple of hours of free surfing lessons with  a professional surfing school before the days main events...

..If you aren't so keen on wrestling a shark, arriving at 12:00 gets you free access to up to 7 hours of informative speaker sessions, hands on experience and great opportunities to meet and network with some leading voices and personalities in the Salesforce development, employment and training sectors.

(You'll also get a free t-shirt, free lunch, and some drinks at the Happy Hour that follows the main speakers of the day!)

If you are thinking of finding new work in the IT industry, or expanding your existing horizons in an existing office/administrative role, this is a brilliant opportunity to see how easy it can be to make waves in the Salesforce world!


(Aberavon Leisure & Fitness Centre – Princess Margaret Way Aberavon Seafront, Aberavon, SA12 6QW)

With speaking sessions from Entrepreneur Anna Bastek and Technology Super-Innovator Dave Carroll, alongside 5 other brilliant presenters, there is a lot to take away from this day.

Meeting with the chief sponsors, such as Mason Frank and Impact IT Solutions at their expo stands will also give you a chance to see the great products, services and software they provide.

All you need to do is sign up now on Eventbrite, and it's next stop - Surf City! 

Friday 19 February 2016

Navigate the Salesforce Advantage

Arrr. Me hearties. Tis time for another Trailhead module review... this time, no battleships, but PIRATE ships, as we Navigate our way through the Salesforce Advantage Sea...


Learn about the key differentiators that drive our success: our core values, innovative technology, and vibrant ecosystem.


So go throw on yer best sailing hat, grab yer cutless and join me on a sailing adventure across all that this great module has to offer!

This here module is a little different to t'others ye might have done in the past.. it's not got the technicals, ye won't be needin' yer fiddly code or clicks, but what you will be gainin' is a mighty haul of treasured information on why Salesforce is the greatest ship to float on that there Internet, both for yourself, and yer piratin' business.

B'fore ye gets to the wheel house though, yer gotta start down scrubbing barnacles off the belly of the boat.. Module 1 covers the 4 cornerstone philosophies of why Salesforce be the best in the market for not only Cloud CRM.. but every part of yer business. Don't fret too hard on the quiz, no-one is getting hung and drawn in this exam, it's as easy as taking candy from a French merchant ship. There be a truly terrifying picture of Marc Benioff from 1999 in there though, so brace yerself for that.

Once yer've snagged yerself a ships wheel for your efforts... why not boast to all your buccaneer buddies over in LinkedIn, with the SSO link. All true pirates use LinkedIn you know.

Module 2 be on all the bits of the great ship Salesforce from the Masts (lets say that's Sales cloud) to the decking (the AppExchange maybe?) it all be there ready and available for you to sale your way to success. A good pirate knows his way around his ship, and this module gives you an idea of how bigger boat you've got. Speaking of size, if ye get yer britches in a twist on the exam in this module... the answers are the longest, most expansive ones ;)

Arrrgghhh!! Whats this?! Does a storm be a brewin'?! Oh... no... it's just the Clouds coming in, the second half of this module explains why not having to worry about all that computer hardware, servers, backup, multiple-OS configuration is so amazing.. Salesforce is one ship that's NOT afraid of a bit of cloudy weather, in fact, it was one of the pioneers of Sailing on the cloud, and will continue to be so for some time.

Answer a couple more questions to get the next bit of yer ship together, the prop, now we're going places!

The next module says it will take 5 minutes, and that's only if you decide to sit and ponder the quote from Parker Harris for 2 minutes... it's a bit of a doozy to be sure, but that's because it's the simplest concept ever - how to trust the Cloud. When you get to the quiz on this module... see if you can work out why I got question 2 wrong:


It's harder than ye be believin'

In learning the value of multitennancy we find out what having all our pirate buddies about is about, and why its actually quite a cool thing. I wish when I lived on my own I had a door man, and if I'd lived in the cloud I could have done.

The next chapter in this module is on MetaData, so we be startin' to get a little more technical..  but there is really only one thing you need to know about this module is that at 1:24 in the video.. a pig uses Salesforce1. I think my next Developer Edition exploration will have to be a farm, I've never done that before! (oh, we're supposed to be pirates aren't we... ahem.. arrrhhhhh). The key to Davey Jones' locker here is that Metadata is everything you have defined in the cloud, and that it is yours, it is safe and secure, but it is based on the same powerful platform that some of the biggest and most successful businesses use.

For a developer style ship mate, this next module is an interesting one, I feel like it gives the world a good impression of what we do, but no-one really likes seeing their job described as being "5 times faster" than usual... I can almost hear my deadlines screeching in around me ;) keep your cannons loaded though and you'll be able to keep those milestones at bay.

I'll also be honest to the pirates code, and say that question three is a tricky one for me, because I freaking love coding. But I kept it together and fired the canon ball to the back of the net for another 100 points, and another badge on my pantaloons.

The final module on this vast voyage starts with Community. This is a personal favourite of mine, as I am almost entirely submerged in what is really a global community of Salesforce developers and experts. As I organise the my local Developer User Group here in Bristol (UK), and attend our User Group, as well as other groups around the country.. I have also had the pleasure of attending Dreamforce in San Francisco, and the MVP summit in the same city.

I have genuinely got to a point now, where it is as easy and quick for me to pop a question on the Internet to get help with a Salesforce question as it is to turn to the people in the room with me.

The final chapter, err.... Meet an MVP?! Well, Hello! If you have made it this far into one of my blog posts, I already probably consider you a closer ship-mate than you'd imagine. Here be my pirate calling card.. get in touch whenever you need!



Captain Simon Lawrence





If you need any other MVPs in the Bristol area, feel free to pop a tweet to my colleagues @adtennant or @jenny_bamber, or indeed dig up Chris Lewis, Matthew Morris or Simon Goodyear.

So that be the journey completed, get those badges on your profile! You're half way to having your own Pirate ship...



Monday 15 February 2016

The way of the Lightning Component

This is a quick walk through of how I wrote my first Lightning Component in Salesforce, to give myself a feel for the process, and develop my own skills in this up and coming technology.

But what to do? I didn't want to actually produce a piece of serious functionality, thats what I do at work all week anyway, but I also didn't want to create a piece of HTML that wrote "Hello World!" in a totally separate and useless app.... and then I had a thought, why don't I write an integration to the Internet Chuck Norris Database, providing a contacts name, and then display a "Chuck Norris" style quote on the contact page...? 



(For those of you who didn't know, the ICNDB provides quotes about Hollywoods most bad ass actor, Chuck Norris, and it of course also provides a RESTful API - to which you can provide alternative first and last names, to receive some JSON with a quote tailored to that person)

So this was a fairly simple example, but it included a web call out, which is always interesting, and also meant I needed to embed the component on a standard view page, and pass information about that record to the component. I felt this was just the right amount of complexity. 

First off then: The component

It seemed logical to start with the component. I did all this work through the Developer Console, so some boiler plate was put in place with me as soon as I selected to build a new Lightning Component from the File menu.

All I needed to do was put some HTML in the aura:component tag, and putting some activity code into the client controller. So some gotchas - you can't make a web callout from the client controller in Javascript, logical I suppose, it is a bit wild - security wise; and a performance liability. I also had trouble getting the function to run from the "init" tag, so I put it behind a button for a while, but eventually it just started working under Init as well. I think perhaps I was just impatient!

ContactChucker.cmp

<aura:component controller="ChuckController" implements="force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="firstN" type="string" default="Chuck" />
    <aura:attribute name="secondN" type="string" default="Norris" />
    <aura:handler name="init" value="{!this}" action="{!c.requestQuote}" />
    <ui:outputText value="{!v.quote}"/>
</aura:component>

In here we have a couple attributes, that bind to the data sent in from the Contact page (details below in the Visualforce section) and then an Aura:handler instructed to execute on init and the output text from the standard UI library for the quote, quite simple in the end.

The "Implements" section uses some standard Component libraries to tell Salesforce this component needs to work on all pages (Visualforce, standard view etc.etc.) and is "Hostable" - which is also something to do with placing it on Visualforce.

The action in the init tag calls the component method requestQuote - as described here:

ContactChuckerController.js

({
 requestQuote : function(component, event, helper) {
        var initAction = component.get("c.getChucked");
        initAction.setParams({ firstN : component.get("v.firstN"), secondN: component.get("v.secondN") });
        initAction.setCallback(this,function(response){
                if (response.getState() === "SUCCESS"){
                    component.set("v.quote", response.getReturnValue());
                }
            });
        $A.enqueueAction(initAction);
    }
})

Just one simple function, which sets up a method call to our Apex controller called getChucked. I think all methods coming from the Apex need to start "get", and I don't know why the c. prefix is required. This had to be like this though because I couldn't call ICNDB from Javascript, so I use standard javascript to pull off an Asynchronous callout,  I can set the parameters by GETTING the values from the attributes on the page, and passing them in with "setParams".. and then in the callback function I use the Component.set method to update the quote in the UI output text element.

Once I had this component ready, I needed to house it in a Lightning Application, which I did so by making a new Application from the developer console, and simply entering:

ContactChuckerApp.app

<aura:application access="GLOBAL" extends="ltng:outApp" >
    <aura:dependency resource="c:ContactChucker" />
</aura:application>

Here I just needed to tell Salesforce the app was available to anything that wanted it, and that it would be output on Visualforce pages (the outApp base controller). That is really it.. In this form, the preview button comes up blank, because the app doesn't actually make a component, just depends on it... but to test it, instead of that being a dependancy, you can actually just include the c:contactchucker tag to initiate the component right in the app.

A little Apex

So I now had a component, but it was trying to use a controller to make a call out that didn't exist.. so we better fix that. Here is the simple controller method to make the call out, as an @AuraEnabled method, and some clever innerclasses to facilitate the JSON deserialiser.

ChuckController.apx

public class ChuckController {


    @testVisible
    private class JsonJoke {
        public String type { get;set; }
        public JokeValue value { get;set; }   
    }


    @testVisible
    private class JokeValue {
        public String joke { get;set; }
    }


    @AuraEnabled
    public static String getChucked(String firstN, String secondN) {
     HttpRequest req = new HttpRequest();
     req.setEndpoint('http://api.icndb.com/jokes/random?firstName=' + firstN + '&lastName=' + secondN);
     req.setMethod('GET');
     Http http = new Http();
     HTTPResponse res = http.send(req);
     JsonJoke jsjk = (JsonJoke)JSON.deserialize(res.getBody(), JsonJoke.class);
     return jsjk.value.joke;
   }
    
}

I hear what you are thinking though, with Apex, we need tests to be able to package or promote this work. Well, don't freak out, there is a really simple test to assert this behaviour that utilises the Apex testing MockHttp library:

ChuckControllerTest.apx

@isTest
global class ChuckControllerTest {


    global class NeverMockChuckService implements HttpCalloutMock {
        global HTTPResponse respond(HTTPRequest req) {
            HTTPResponse res = new HTTPResponse();
            ChuckController.JokeValue jv = new ChuckController.JokeValue();
            jv.joke = 'MS Dynamics';
            ChuckController.JsonJoke jj = new ChuckController.JsonJoke();
            jj.type = 'joke';
            jj.value = jv;
            res.setBody(JSON.serialize(jj));
            return res;
        }
    }


    @isTest
    public static void auraComponent_HttpMocked_ReturnsResult() {
        Test.setMock(HttpCalloutMock.class, new NeverMockChuckService());
        String quote = ChuckController.getChucked('Simon','Lawrence');
        
        System.assertEquals('MS Dynamics', quote);
    }
    
}

There's 100% coverage in your pocket right there.

We have a bunch of code then, and basically a working component, but we have a little more to do to get it on the page and operating. First we need to get it into a chunk of Visualforce, which means two things: Making a Visualforce page (that uses the Contact controller, so it can be put on the details page) that actually renders the app and component, and then passing the Contacts name down into the app so it can be sent to ICNDB... This is what the Visualforce page ended up being:

ChuckPage.vfp

<apex:page standardController="Contact">
    <apex:includeLightning />
    <div id="chuckLine" />
    <script>
        $Lightning.use("c:ContactChuckerApp", function() {
          $Lightning.createComponent("c:ContactChucker",
          { firstN: "{!Contact.firstName}",
            secondN: "{!Contact.lastName}" },
          "chuckLine",
          function(cmp) {}
          );
        });
    </script>
</apex:page>

This is a standard (and apparently famous) snippet for embedding a Lightning Component on a Visualforce page. Include the Javascript, set up an empty div container, and then use that Script tag to setup an instance of your app, and then inject the dependant component... (don't get too bogged down in namespaces here, it's all just "c" it turns out). The second parameter of the createComponent is a Javascript object that is bound to the attributes of the Component above.. gotcha: do not use reserved words or field names here, like 'contactName' as an attribute, or it will never work! I spent ages wondering why I couldn't pass the contact name in, until I switched over to firstN and lastN as my attributes, contactName simply would not be set.

The last two things to do now then is to put this piece of Visualforce on the standard Contact page layout, and ... have you realised the last thing? You need to make the icndb.com domain a REMOTE SITE in remote site settings, or Salesforce won't be allowed to talk to it.

That is it though! you now have your own bad-ass Chuck Norris quotes about your Contacts in Salesforce, curtesy of Lightning Components. Here are some personal favourites...