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.