Monday, 21 January 2013

Is it time to move house?

Once upon a time there was a seismic event known as the dotcom boom where all business moved to the internet, ecommerce sites led the way and were the tool of the time to leverage this new powerful new sales channel. As the tools and methodologies matured the solutions became more sophisticated and allowed ever more data to be captured about the customers of these businesses and what products or services they were purchasing right down to their birthdays. For a time, this was then simple, normal, the standard approach. The customer used the internet, came into a high street store or gave them a call on the phone. The systems were integrated to allow the same customer information to be available to telephone operators (Sales, Customer Service etc...), store clerks and the online decision making systems that would offer contextual offers or dynamic discounts based on the customer currently undertaking that journey.

For a while this worked well, Marketing teams got better at analysing the data and segmenting it into manageable information that was actionable. User experiences became more tailored and customised, offers and advertising were more targeted to the user and began to get a better return as the offers were of interest to the users and slowly but surely the picture became as complete as possible for these businesses operating in the internet space. Customer service was considered value add, yes you may lose a single customer if you didn't get it right, but it wasn't like word of mouth extended more than a handful of people.

...Fast Forward 15 years and we are right in the middle of the advent of the social media eruption...

Suddenly Twitter, Facebook, LinkedIn and other tools allowed individual people more power than they have ever had before. The social media space suddenly gives the individual a voice that everyone can hear and is fundamentally changing the face of Customer Service and Brand Management. It blows open old ways of doing business via the internet and highlights massive gaps in the understanding businesses have of their customers. A great example of this was highlighted to me the other day by a colleague working with a massive global Enterprise customer.

One of the tranches of business this customer provides is printers and printing supplies to both businesses and individuals and traditionally their customer service operations were geared towards providing a better level of service to business customers as they traditionally did the large, considered purchases and the business was keen to provide them with exceptional post-sales service. Social Media has seismically rearranged the landscape here! Ever since a part time nanny called Molly Katchpole, businesses can no longer afford to ignore the individual as they now have the power to do massive damage to brands and share prices. Customers now expect the highest level of customer services from their product and service providers.

Now how can businesses do this? How can you now get to know a customer who has access to multiple channels of communication? An individual who can speak to the masses every bit as effectively as your marketing department, and how can you learn all you need to know about this customer to give them the service they require?

Yes, there are tools out there to help you do this. Radian 6, Salesforce, Buddy Media, BlueConic and Eloqua being the first few that sprint to mind but the most key word there is that they are tools!!! I myself am not particularly gifted in the realms of DIY although I have every manner of tool conceivable, I have Hammers, Pliers, Drills, Spanners, tools for tiling, tools for plastering, tools for woodwork, tools for plumbing, tools for brickwork and masonry and a whole separate toolbox for stuff I'm not quite sure what they are for but they look as if they have been used at some point in their life. My point to this reference is that I wouldn't decide one day to build a house based on the fact I have the correct tools for the job. I admit I can Google and watch YouTube videos to tell me how to lay foundations, lay bricks, insulate walls, put in a central heating system but the simple fact of the matter is I would be very quickly swamped with data that I cannot make any sense of and certainly couldn't be able to action as I'd find myself plastering walls before putting in the electrics. The resultant mess would be catastrophic.

To expand my analogy, to get to know your customer in an ever changing environment you need to think how your house needs to be built, who will be living there(Individuals, personas and customer demographics), what sort of style they like (What products or services interest them), what rooms will be necessary (Marketing Segmentations). Only then once you have thought about this you can begin the journey to truly knowing your customer, knowing what makes them tick, knowing what they buy, how they behave, who they interact with, what they are saying about you. The old dotcom houses were great at their time, they were the right size, the walls were all magnolia and the one size fits all approach seemed to be more widespread than you would imagine but these houses are getting old, they are no longer big enough, they no longer do the jobs we need them to do. In short, new houses are needed for modern times.

With the ever increasing amount of data being gathered about customers from Tweets, posts, blogs, cookies, online purchases etc. it would be very easy to take all this and try and pack it on, build an extension if you will pardon one more stretching of the analogy but we the advent of Social Media, I believe it's time to think about moving!

Wednesday, 16 May 2012

Working with Content in Apex

So, it's been a long while since I last posted here an this one is going to be a short one for the techies amongst us. I recently had some work to do around Content and using a trigger to take the latest version of a template and create a copy linked to a custom object and also share it in a different workspace as a specific piece of documentation. Now, if you haev been around Salesforce long enough, you'll know that when Content first came out it was completely untouchable with Apex and today, I am happy to say, this has now changed. Onto the solution... I first created a custom setting which would hold the Ids of the Workspace(s) I would be using (to get around the hard coding issue and depolyment from sandbox to production) and wrote some very simple code to retreive this:
 public static CPM_Documentation_Settings__c getWorkspaceIds() {
     // Retrieve the custom setting and get the Id of the workspace
     CPM_Documentation_Settings__c documentSettings = [SELECT Document_Template_Workspace_Id__c, Document_Workspace_Id__c FROM CPM_Documentation_Settings__c][0];
     return documentSettings;
     
    }
Whilst not very robust or defensive it met the immediate need to get the Ids back that I needed. The next job was the meat of the issue, how to pick up the latest version of any templates and create new versions in the documentation workspace and link them to the custom object. The First thing I needed to do was get all the latest versions of the templates:
    // Get the Workspace
        CPM_Documentation_Settings__c settings = ProjectTriggerUtilities.getWorkspaceIds();
        
     ContentWorkspace templatesWorkspace = [SELECT Id FROM ContentWorkspace WHERE Id = :settings.Document_Template_Workspace_Id__c];
     ContentWorkspace projectWorkspace = [SELECT Id FROM ContentWorkspace WHERE Id = :settings.Document_Workspace_Id__c];
        
        // Get the list of document templates and their current published version Ids
        List templates = [SELECT ContentDocumentId FROM ContentWorkspaceDoc WHERE ContentWorkspaceId = :templatesWorkspace.Id];
        List templateIds = new List();
        for (ContentWorkspaceDoc doc : templates) {
         templateIds.add(doc.ContentDocumentId);
        }
        List contentDocuments = [SELECT LatestPublishedVersionId FROM ContentDocument WHERE Id in :templateIds];
        
        List latestVersionTemplateIds = new List();
        for (ContentDocument cs : contentDocuments) {
         latestVersionTemplateIds.add(cs.LatestPublishedVersionId);
        }
Now that I had a collection of all the latest versions of templates I simply needed to create the new versions linked to the custom object:
//loop through all the templates and pull back the latest published version of each of them
        List latestVersionOfTemplate = [SELECT c.VersionData, c.Title, c.Supplier_Brand__c, c.Relevant_Sector__c, c.Reference__c, c.PublishStatus, c.Printed_Version_Available__c, 
                                                               c.Printed_Format__c, c.PositiveRatingCount, c.PathOnClient, c.Origin, c.NegativeRatingCount, c.Industry_Sector__c, c.Id, c.FirstPublishLocationId, 
                                                               c.FileType, c.FeaturedContentDate, c.FeaturedContentBoost, c.Description, c.Customer_Facing__c, c.ContentDocumentId, c.Classification__c, 
                                                               c.Brand_Relevance__c 
                    FROM ContentVersion c
                    WHERE ID in :latestVersionTemplateIds];
        for (Project__c p : projects) {                    
         //create the new documents from the templates
         List newProjectDocuments = latestVersionOfTemplate.deepClone();
         for (ContentVersion cv : newProjectDocuments) {
          cv.FirstPublishLocationId = settings.Document_Workspace_Id__c;
          cv.project__c = p.Id;
          cv.ContentDocumentId = null;
          cv.Title = p.Project_Name__c + '_' + cv.Title;
          cv.Description = '';
         }
         insert newProjectDocuments;
        }
And there you have it, we now have the ability to create new content based on existing templates that exist in SFDC content. There is still some fun to be had unit testing and there are still some gotchas in there they are easy to workthough. If you have any questions please let me know by commenting and I'll do my best to steer you in the right direction.

Tuesday, 28 February 2012

Why get SFDC certified

As I sat down to take my Sales Cloud Certified Consultant exam, I adjusted my web cam for the 14th time and tried to relax and remember every single aspect of the Salesforce.com Sales Cloud and Sales Automation proposition.

I tried to recall Wealth Management, Person Accounts, Lead Management, Roles, Profiles, Territories, Account Hierarchies, Sales Teams, Account Teams, Queues, Sharing groups, queues, Sales Processes, Pipelines, Forecasting, Custom Forcasting, Products, Assets, Opportunity Products, Product Schedules, Validation Rules, Formula Fields, Workflows... The list just seemed to spiral out of control and after a short panic followed by a deep breath, I hit the start button and commenced.

A short while after I had finished I decided to think why, oh why had I just put myself through the tortuous Salesforce.com certification process again! I takes up immeasurable amounts of your own time to revise the subject matter, clogs up my Kindle as I download the entrire help PDF onto it for some 'light' bedroom reading and causes me to say apparently strange things to my wife who, until recently, had no idea you couldn't enable Territory Management unless you had also enabled customised Forecasting.

Then, in a moment of clarity I knew why we do it!

Salesforce is quite frankly one of the most powerful and dynamic applications in the world today It has so many strings to it's bow that it is quite frankly difficult to keep on top of them, even if you are a specialist in the technology. Bearing this in mind, it's important to remember that customers will generally tend to buy Salesforce.com as a CRM application, let's face it, with a simple enough sales process you can have SFDC up and running for Sales Automation in a matter of hours and fully configured with reports, security and all the bells and whistles in about 10 days. Where it gets tricky however, is when the customer wants to leverage the potential of the SaleForce.com platform.

I have often thought one of the major strengths of SaleForce.com is often used by people to turn it into a weakness of the plaform. I'm sure you have heard Salesforce.com employees, partners and consultants religeously chanting the following mantras:

'80 / 20 rule

'CLICKS NOT CODE'

and as cliche as it may sound this is more than a mantra, it's actually best practice and combined it gives you the split of how the majority of successful implementations should be done '80% clicks to 20% code'. This however sometimes isn't followed! People starting out on Salesforce are oftern ex-Java or .Net developers and are very comfortable in an IDE such as Eclipse or Visual Studio. They don't like the standard Salesforce layouts, find configuration boring and unchallenging and are keep to jump into writing triggers, classes, components and VisualForce pages. They ignore the rich functionality of Workflows, Formula Fields and Roll-up summary fields. They have no inclination to learn about Divisions, Territories, Wealth Management, Person Accounts (I won't go through the list again :) ). They write hundreds and thousands of lines of code, massively increase the complexity of the implementation and more critically, irreperably impair the flexibilty and dynanism of the platform.

At this point I will now return to the original question posed at the beginning of this blog, I must assure you I haven't actually digressed as far as you would think.

In order for a Salesforce Consultant to be able to deliver the best possible solution for the customer, they must first know platform to an obsessive level. They need to know the latest features in the new release. They need to know what can be done with Workflows, what can be done with formula fields. New skills have to be used to get the best from the framework and this is where the certification comes into it's own.

Customers don't want to know all of this, they have day jobs, they are worried about the day-to-day running of the business and don't want to become Salesforce consultants. They need to know that they are getting real platform experts, people who actually have recognised and standardised qualifications in the subject matter. Now, to put a slight mocker on this, having a certification does not necessarily make you a good consultant and on the converse side not having certifications doesn't make you a bad one either but, having those certifications proves to the customer (and a prospective employer) that you at least know enough about the platform to pass those exams. You have proven that you know how what features are available, what can be done with configuration alone, how you can combine features to build solutions, when you have reached the limits of the platform and need to start thinking about development. At the end of the day it's an insurance policy for Salesforce.com owners and stakeholders that you are getting someone who actually knows the platform to a good enough degree to deliver a maintainable, scalable and flexible solution that meets your requirements without costing the Earth.

Monday, 9 January 2012

The Speed of the Cloud

It's been a while since my last blog as I as I have been busy working my two jobs as first a daddy and husband and secondly as a TA at Astadia. So apologies for the delay and here goes. When I started out as a young, wet behind the ears graduate as a developer many years ago, before Agile, before SaaS, before the cloud it was a well known cry of business all over the world that IT could not react quickly enough to service the business. Typically any new IT solution was completely handicapped from the start. Using the immensely popular methodology of the time, the project would started using the waterfall approach. Several weeks upfront on analysis and design, followed by another few weeks getting the design signed off and then over to the developers. Following any number of months, the design would be subject to significant and expensive changes as the business needed to react to new processes, new legislation, new products / service etc... This made IT projects a massive headache, it was a real challenge to deliver solutions on-time that:
  1. Met the original design + and any accepted change requests
  2. Was within the budget
  3. Was devlivered on time
  4. Was actually what the business needed
1 & 4 could not be relied upon to be the same thing! No matter how hard you tried, the design was always a point-in-time reference to the business requirements at the time of the projects beginning! No matter how good the change management process was, talk of phase 2 or release 2 always started to creep into conversations as the changes became more and more complex. Here we are now however in 2012 and now I believe the tides have changed, the roles have reversed, the shoe is on the other foot :) In the past year I have started to hear an almost totally unheard situation. The business are not able to adapt to the rate of change from IT! In my current project where myself and another TA from Astadia (Twitter @stuagare and blogger ) have been developing enterprice solutions for a Sales and Financial applications on the SalesForce.com for a telco client with a multi-continentental presence. We, along with the assistance of development teams from many different shores and timezones have worked with the business to capture their reqirements and build them a solution to allow them to massively update and automate complex sales processes. These complex and powerful solutions have been designed, developed and deployed in such a short timescale that the business are having real problems reacting to the speed of IT. The main reasons of this have been
  • An Agile based project methodology tailored specifically by Astadia
  • The SalesForce.com and Force.com platforms
  • Business stakeholders, decision-makers and subject matter experts being heavily involved throughout the entire project.
So with fresh-faced enthusiasm and overwhelming optimism I am now looking forward to a change in my career. I predict that 2012 will be the year where the old problems and headaches will become a distant memory,
  • project timescales will reduce significantly as more and more companies leverage the power of Cloud and SaaS solutions.
  • 1 Year+ projects will be consigned to be the exception rather than the rule
  • Project change requests will significantly reduce, this will have the knock-on effect of lowering risk to timescales and budgets
  • Delivered solutions will be more complete, more in-line with what the business need today, rather than 6 months ago when the requirements were captured
The new problems will be lesser in comparison, the softer skills of the consultant will come to the fore, adoption assistance, training and user support. 2012 in the cloud will see ever closer alignment of business and IT and SalesForce.com and the Force.com platform will be a massive part of this.

Wednesday, 16 November 2011

VF Woes

Very quick blog this week and it's around an issue I had allocating dynamic Ids to Apex Input fields.

I had a recent requirement that needed me to change the values in some input fields in a targetted way on a VF page. My first thought was to assign a dynamic ID to the <apex:inputfield> only to find that you need concrete values in here.

Found a clever way round this that allows you to find fields by their <apex:inputfield styleclass="{!variable}"

As the JavaScript function getByElementClass is not support in all browsers I needed to write something quick and functional (read dirty) that did the job without using any external libraries or Frameworks i.e. jQuery Here is a very simple JS function that will retrieve all the elements of a certain classname to allow you to 'do stuff' to them.
function getElementByClassName(cl) {
    var elements = [];
    var elem = document.getElementsByTagName('input');
    for (var i = 0; i < elem.length; i++) {
        if (elem[i].className.indexOf(cl)!=-1) elements.push(elem[i]); 
    }
    return elements;
}; 
Not rocket science but you can extend it to use regular expressions etc... and all you need to do it pass it the classname you are looking for. Won't solve a lot of problems but it definitely solved one for me today :)

Thursday, 3 November 2011

What did that chap just say?

Business and IT, two bodies working for the same company on the same project separated by a common language. How many times in your working life have you as a business user come out of a meeting or workshop and thought,

"What on Earth were those techy guys going on about? A workflow with a field update and an outbound call to a web service to integrate with the outlying systems via the middleware tier, I have no idea what that means"

You are not alone in this, many's the time I have left a workshop and had a developer ask what the business users meant by:

"We need a solution which will enable our back office staff to get all the information necessary for fulfilment without having to go back to the front office B2B reps to get extra detail."

Neither of these statements are complicated per se but, one of my jobs as a consultant is to make sure that when communications happen between technical resources and business users that they communicate in a common language and my role is interpreter.

Luckily this is not a difficult problem to overcome. All you need to do is invest a little time in the technical team prepping them. Here is a short list of what I like to do to better faciliate the conversation
  1. Get a list of all the issues that the technical team need to discuss up front, find out what the developer needs to know to complete the work. This way, you will be having the conversation.
  2. Coach/Mentor your technical team. Have a pre-meet with the team to make sure there are some simple ground rules laid down:
    1. Under no circumstances should the developer talk about code or offer to show it
    2. Business users do not want to hear about the details, Workflows, Classes, Triggers, Unit tests. None of these should be mentioned
    3. Where appropriate, try and ask the question to your own consultants. It’s their job is to translate between Business and IT
Communications between Business and IT need not be a stressful ordeal. With a little preparation then it can become a productive and stress-free experience.

Monday, 17 October 2011

The Lazy Unit Tester

My take on unit tests? Essential!

Never mind that SalesForce.com forces 75% code coverage on any code written. Even if this mechanism wasn't there, I would still insist on them being present on any solution implemented by myself or my team.

A unit test is, at its most basic level, code that tests code! It's not a replacement for smoke, functional or system testing; it's a mechanism which helps improve the quality of code written by developers.

If you’re building a car, it’s the sum of all its parts. The parts are manufactured individually, then put together and at the end of it you have a working car! Quite a simple process, like a jigsaw puzzle, but a lot can go wrong in this process.

Let's take the wheels on the car. For the car to run you need four wheels, each with tyres. They all need to be the correct size, shape and inflated to the correct pressure to be useful. If one of those wheels is square, the wrong size or is flat then this will affect the operation of the car and make it less than desirable to drive or own.

When buying a new car, you hope the manufacturer tests the individual components (in this example the wheels), as well as the overall function of the car.

Now, onto the geekery, let's take this code example

public class Wheel {
    public static String defaultBrandName = 'Default Tyres Inc';
    public static int defaultSize = 14;
    public static double defaultPressure = 33;

    public String brandName;
    public int size;
    public double pressure;
 

    public Wheel() {
        this.brandName = defaultBrandName;
        this.size = defaultSize; 
        this.pressure = defaultPressure;
    }

    public Wheel(String brandName, int size, double pressure) {
       this.brandName = brandName;
       this.size = size;
       this.pressure = pressure; 
    } 

    // Some Accessors and Mutators for the instance variables
}

public class WheelFactory {
    public static Wheel getWheel() {
        return new Wheel();
    }

    public static Wheel getCustomWheel(String brandName, int size, double pressure) {
        return new Wheel(brandName, size, pressure);
    } 

}
It's quite clear how this now works. We go to the wheel factory and either ask for a default tyre or we specify what kind of tyre we want, as the meerkat says 'Simples'. but what would be the best way to test this to enable me to deploy it to a SDFC production org? Not much I hear you say, but here is an example of the type of thing I have seen.
@isTest
public Class WheelFactoryTest {

    public static testMethod void myUnitTest() {
        Wheel w = WheelFactory.getWheel();
        Wheel w1 = WheelFactory.getWheel('Pirelli', 20, 33);
    }
}
And there is it, as far as Force.com is concerned, a perfectly valid unit test! It makes the 75% test coverage requirement and took about 30 seconds to write. Job done! Let me ask you this though, what is my unit 'TEST' actually testing? The simple answer is that it's testing that the WheelFactory and Wheel classes compile and can be called. It's quite frankly a waste of 30 seconds and this test is useless! Is a Wheel being returned? or is it returning a null? What brand is it? What size? What pressure? We just don't know from this test! Below is what I would consider a better test of this:
@isTest
public Class WheelFactoryTest {

    public static testMethod void wheelFactoryGetWheelNoParamsTest() {
        Wheel w = WheelFactory.getWheel();
        System.assert(w != null);
        System.assert(w.getBrandName() == Wheel.defaultBrandName);
        System.assert(w.getSize() == Wheel.defaultSize);
        System.assert(w.getPressure() == Wheel.defaultPressure);
    }

    public static testMethod void wheelFactoryGetWheelWithParamsTest() {
        String brand = "My Brand";
        int size = 17;
        double pressure = 35;
        Wheel w = WheelFactory.getCustomWheel(brand, size, pressure);
        System.assert(w.getBrandName() == brand);
        System.assert(w.getSize() == size);
        System.assert(w.getPressure() == pressure);
        
}
Hopefully you can see the improvements here?
  1. We are testing each method in a clearly separate way so if one method fails we know instantly which one is broken
  2. We are using asserts to guarantee that we are getting the correct results! When you see a unit test with no asserts you need to change that! 95% of the time there is no excuse for a unit test with 0 assertions this is testing more than just coverage!
  3. We are protected from change! Because we are using the static default variables from the WheelFactory class in our tests, if those defaults change our unit test does not need modifying, this is basic coding 101, don't use magic numbers!
  4. I am actually testing that the tyres are the correct size, pressure and brand! Wouldn't you do that in real life if you were buying tyres for your own car?
Hopefully people will find this useful and when they get given a unit test to write will do the right thing and do it properly and understand the importance of a well constructed unit test!