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.

<apex:page controller="ReassignEventController" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Re-assign Event to User" >
                <apex:outputField value="{!event.Owner.Name}" />
                <apex:selectList label="Assign to" id="assignTo" value="{!assignTo}">
                    <apex:selectOptions value="{!users}" />
                </apex:selectList>
                <apex:commandButton action="{!reassign}" value="Re-assign" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

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

The Road to Become a Salesforce Developer

If you are considering becoming a Salesforce / Force.com developer and confused how to get started then have a look at my chart that shows the skills you need to learn and the approach I am taking.

I will post enhancements to this from feedback and my own experiences.

The Road to Become a Salesforce Developer

Road to Dreamforce ’13 Episode 1: What’s New at Dreamforce?

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">&quot;{!Account.BillingPostalCode}&quot;</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">&quot;map_canvas&quot;</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(<br />             {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> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 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.

Released Expensy, my first Windows Phone App

todayI originally wrote Expensy for myself as I just wanted to keep track of my total outstanding Cash. I didn’t want to know about what money was in which account. Just a simple view of a total amount and a quick way to add spending and adjust the balance.

That’s how Expensy was conceived and I was really interested to try my hands at developing for the Windows Phone platform as I love the interface. Its so much cleaner and different to the typical icon based OS’s.

It’s now available free on the app store and hope you enjoy using it.

http://www.windowsphone.com/en-gb/store/app/expensy/d22afcc1-24df-42f2-a283-1b22e6095435

Top Apps RIM Need to Release with BB10

bb10 The week has finally arrived where RIM will showcase there new BB10 OS and devices on 30th January. I truly believe that RIM have got this one totally right, from the cool and smooth OS to the way they treat developers like myself.

I have been thinking about the types of apps I use on my other devices which I would need to make BB10 work for me on all levels. Here’s the list and why not leave a comment and on what apps you want on the platform:

  • Google+
  • Facebook
  • Twitter
  • Google Reader App with offline sync
  • Natwest App
  • Linkedin
  • Engadget
  • The Verge
  • Spotify
  • Podcast Player / Manager
  • Toshl
  • Skype
  • Lumosity
  • Pocket
  • Dropbox
  • Kindle
  • Runtastic
  • Candy Crush (Yes I am addicted)

ApplicationCraft Cool New Look

I was loving the home page released recently by ApplicationCraft.com and now they have made some further UI enhancements that make me happy.

ApplicationCraft Console

 

This platform for developing my mobile apps just gets better and better and now they also support Windows Phone. All I need now is them to support BB10 and I will be ecstatic.

 

Goals are for Geeks

http://openphoto.net/volumes/sizes/miro/23992/1.jpg

I have been soul search in the new year, considering what I would like out of the next chapter in my life. I thought I would share these long and short term ideas with you in the hope that it could give you some food for thought.

  • Take time out with others interested in Landscape Photography.
  • Write an online novel for fun.
  • Get more involved with open source projects.
  • Get back into PHP and use C9 so I can Code Anywhere in the world.
  • Create some fun HTML5 projects for mobile.
  • Spend time with other developers and designers.
  • Fly a real Boeing Simulator.
  • Take up Tai Chi.

What are your goals? If you don’t have any then now is the time to start. You need them to motivate yourself and it gives your mind structure.