Salesforce Click first Approach

OK so I did take the title idea from .NET Entity Framework Code first Approach but it works so don’t shoot the messenger.

2016-11-22 12_47_14-WX21-Features.pdfYes I am a .NET developer and have been for many years but the problem with coding on that platform is the amount of code you have to write to accomplish a task. This is why I also use a development tool called WinDev/WebDev from PC Soft to build solutions as the approach they have taken is the provide components that solve common requirements. They also go down to the level of code and to make simple methods to code that will also achieve results quickly, like displaying a Google map or creating a stack graph in a dashboard.

Salesforce has the same approach to the click first approach, allowing you to implement business requirements with a minimal or no code at all. To me this is the future of business software development where you only have to code the unique aspects of a solution rather than having to build a complete platform.

2016-11-22 12_42_21-Process Builder _ SalesforceThis is one of many reasons I have moved to Salesforce and the incredible work they are building in the Lightning platform. Yes I know there are aspects in Lightning that are still not complete but the future for Lightning components is very exciting for a developer like myself, giving me the ability to componentise UI and make that available to users on web and mobile platforms. Then on the back end you can develop the business functionality using Process Builder to visually implement logic.

For example I keep ideas for projects but sometimes I forget about them, so I wanted to be reminded if I had not looked at them for a while. This took just a few minutes to implement and now I get a cool reminder in my Chatter feed if I have not viewed an idea for more than 30 days.

When Click does not go far enough for you to complete your implementation then you still have Apex and JavaScript to work with. I personally don’t use the Force IDE but prefer to use a combination of the Developer Console and Cloud 9 IDE. I like to keep everything in the Cloud, even my IDE, which gives me the best flexibility and portability to code wherever I am.

If your a developer and interested in this approach then why not give it a try, just go to developer.salesforce.com and sign up for a developer account now. If you have any questions of need advice then there is a fantastic community of Salesforce Developers and Admins or just drop me a message.

Happy clicking!!!

New Trailblazers Profile & Dashboard

I’m a big fan of Trailblazers for learning new features on the Salesforce/Lightning platform and the topics are growing for both Admins and Developers. Their are even trails for release plans like Winter ‘17.

A new update to the profile and dashboard have made it even more exciting to promote your Trails and Badges you have received.

2016-11-22 10_41_24-Program Manager

This update has made me more determined to learn more through Trails and increase my knowledge, keeping up to date with all the latest features added to the platform and techniques to advance myself. If you are not used to this type of online learning experience then persevere as you will enjoy the process once you get into the swing of it.

The major advantage to training in say a video tutorial format is that with Trails you are reading the material to learn but then for many sections you will actually complete practical exercises in a developer org, which will be checked that it has been completed before you move on. This actual doing rather than watching or just reading is a powerful way to learn and remember what you have learned.

Here’s my Trailblazer profile if you want to watch my progress:

https://trailhead.salesforce.com/users/profiles/005500000060ZVrAAM

Happy Trailblazing!!!

A Few Tips When Developing Lightning Components in Salesforce

UPDATE: Well it looks like I was wrong about appHostable as this actually works when I created a new developer instance. So looks like even though my original instance was on 16 it doesn’t have everything enabled. All good learning experience.

This week I have been diving into developing Lightning Components and have been really excited how I can build some common business UI as a re-usable component I can just drop onto the Lightening App Builder page.

L1

The above image shows a test component I originally created when I was learning how to build one. It took me a little while to get things working due to changes in Salesforce software releases and working out what was the old way to code against what was new.

Interestingly if you watch the videos in the Lightning Components Trailhead the code shown in the video is out of date. I guess as things are still being developed on the platform, its difficult to keep in line.

First thing to watch out for is the implements attribute on aura:component. Originally it looked something like this:

<aura:component controller=”ContactController” implements=”force:appHostable” >

In the release 16 I am using the force:appHostable is now:

<aura:component controller=”ContacController” implements=”flexipage:availableForAllPageTypes” >

So be aware of this as your component won’t show in the list of Custom Components if you use the old implements.

The other tip is that you no longer need to create a Lightning Component Tab to implement your new component. This option is no longer available in the Setup / Tabs section and you should just create a Lightning app page, where you will automatically see your component in the left panel.

I hope these few tips help you as they were a couple of annoyances for me when I started out coding the components. If you have any questions of further tips then please leave a comment.

 

Salesforce – Re-assigning Event Re-occurrence Instance

Utilising the Salesforce Calendar for events has many benefits compared to using Outlook.

One of my clients came across a limitation recently when they create a weekly re-occurring event for their team member. The problem is that when the staff member cannot attend the appointment they then need to re-assign it to someone else.

With the current version of Salesforce you cannot do this, you can only reassign the complete series to someone else.

The good thing is that with a bit of research I found that each occurrence is a record. So my first attempt was to find the event and then using a Visual Force page I asked who they want to reassign it to.

I wrote some Apex code to update the record to the newly assigned user, but the Salesforce business rules do not allow this.

So the solution was to clone the event into a new object, delete the original and insert the new. This worked beautifully.

public class ReassignEventController
{

    public String assignTo { get; set; }

    public List getUsers() {
        List options = new List();

        for(User u :[SELECT Id, Name FROM User]) {
            options.add(new SelectOption(u.id, u.Name));
        }
        return options;
    }

    public Event getEvent() {
        return [SELECT Id, Description, Owner.Id, Owner.Name FROM Event
                WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public PageReference reassign() {
        System.debug('Save clicked: ' + assignTo);

        Event ev = [SELECT Id, WhoId, WhatId, Subject, 
                    Location, IsAllDayEvent, ActivityDateTime, 
                    ActivityDate, DurationInMinutes, StartDateTime, 
                    EndDateTime, Description, AccountId, OwnerId, Type, 
                    IsReminderSet FROM Event
                WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        ev.OwnerId = assignTo;

		Event ev2 = ev.clone(false,true);
        ev2.OwnerId = assignTo;

        Insert ev2;

        Delete ev;

        PageReference redirecturl = new PageReference('/' + ev2.Id);

        return redirecturl;
    }
}

Once the event has been created then it redirects to the newly created one details page.

The Visual Force page is very simple and I will probably include this in the Event details page.


I hope this helps you if you come across the same situation too. Leave a comment if you need help.

Integrating Google Maps V3 into a VisualForce Page

I recently had a requirement to implement a Google Maps view for an Account and thought I would share the code I wrote to implement this functionality.

Firstly I needed to create a Visual Force Page containing the same structure as the default page, which is easy with just one line of code:

<span class="kwrd">&lt;</span><span class="html">apex:detail</span> <span class="kwrd">/&gt;</span>

The rest of the implementation requires a bit of Javascript to convert the UK Postal code into coordinates and then generate the map.

To convert a Postal code into coordinates you need to use the geocoder object:

<span class="kwrd"> var</span> geocoder = <span class="kwrd">new</span> google.maps.Geocoder();
 geocoder.geocode({
   address: <span class="str">"{!Account.BillingPostalCode}"</span>
   }, <span class="kwrd">function</span>(locResult) {
     <span class="kwrd">var</span> lat1 = locResult[0].geometry.location.lat();
     <span class="kwrd">var</span> lng1 = locResult[0].geometry.location.lng();
     <span class="kwrd">var</span> myLatlng = <span class="kwrd">new</span> google.maps.LatLng(lat1, lng1);
     <span class="kwrd">var</span> myOptions = {
       zoom: 14,
       center: myLatlng,
       mapTypeId: google.maps.MapTypeId.ROADMAP
     }
     <span class="kwrd">var</span> mapComp = document.getElementById(<span class="str">"map_canvas"</span>);
     mapComp.style.width = <span class="str">'900px'</span>;
     mapComp.style.height = <span class="str">'500px'</span>;
     <span class="kwrd">var</span> map = <span class="kwrd">new</span> google.maps.Map(mapComp, myOptions); 
     <span class="kwrd">var</span> marker = <span class="kwrd">new</span> google.maps.Marker(
             {position: myLatlng, map: map, title: address});  
                 
 });

The code above also generates a map object which can be rendered on the page.

The complete code sample can be downloaded here (don’t forget to put your own API key into the code.

image

Button Click Admin Podcast

If you are into Salesforce and Force.com like I am then I highly recommend you listen to the the Button Click Admin Podcast. Mike and Jared to an amazing job talking to people in the Salesforce community

logo

I especially love hearing at the end of each podcast when they ask the interviewee what their favourite Dreamforce moment was.

Hop along to http://buttonclickadmin.com to subscribe to their podcast. I also recommend reading the 5 tips to landing a Salesforce.com Admin job

Salesforce Chatter Triggers

Today I wanted to create an app that would allow me to add my activity so that I can analyse my time at a future date. I started my trusty IDE to start mocking up the idea when I had to step back for a moment and think there must be a simpler way to do this.

I use Salesforce for managing my projects and I usually post chatter messages to myself and others. What if I could post a custom # message that would be intercepted and posted to a custom object.

No problem… I created a custom object called Activity:

image

Then all you need to do is go to Customize > Chatter > Triggers and add a new trigger on the Feed Item.It’s then a matter of looking for a #activity tag in the feed item body, pulling the entry out and inserting it into my Activity custom object.

<span class="lnum">   1:  </span>trigger ActivityPost on FeedItem (after insert) {
<span class="lnum">   2:  </span>    <span class="kwrd">for</span> (FeedItem f : trigger.<span class="kwrd">new</span>)
<span class="lnum">   3:  </span>    {
<span class="lnum">   4:  </span>        <span class="kwrd">if</span> (f.Body.startsWith(<span class="str">'#activity'</span>)) {
<span class="lnum">   5:  </span>            funcoder__Activity__c a = <span class="kwrd">new</span> 
                                 funcoder__Activity__c (
<span class="lnum">   6:  </span>                Name = f.Body.replace(<span class="str">'#activity'</span>,<span class="str">''</span>)
<span class="lnum">   7:  </span>            );
<span class="lnum">   8:  </span>
<span class="lnum">   9:  </span>            insert a;
<span class="lnum">  10:  </span>        }
<span class="lnum">  11:  </span>    }
<span class="lnum">  12:  </span>}

Now just go and enter a chatter message, for example #activity Developed an activity application in Salesforce.