I’m at the TopCoder Open this week. OMG!

November 13th, 2013

Busy, busy week right before Dreamforce! With our acquisition of TopCoder, the CloudSpokes team is part of the TopCoder Open (TCO), an annual event which features algorithm, design, and development competitions in a tournament format. We’ve brought in nearly 125 of the best developers and designers from around the world to participate in 3 days of competitions.

I’ve never been to a TCO before and was blown away by the spectacle and sheer awesomeness of the competitors. From “marathon matches”, “mod dashes” and the “SuperAwesome API Cloud Mashathon” there is something always going on. Just to give you a taste of the atmosphere, here’s a short recap of day one’s marathon match.

For the first year we have a cloud hackathon event called the “SuperAwesome API Cloud Mashathon”. Participants spin our “API Wheel of Awesomeness” and must use two of the three APIs selected in their application.

Unfortunately, I’ll only have a couple of days to recover before Dreamforce so if I’m dragging around the DevZone, you know why.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Categories: Salesforce

1 Comment

How about using Docker for Force.com Development?

October 31st, 2013

Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere. The great thing about these containers is that they encapsulate any payload and runtime dependencies, and will run consistently on and between virtually any server.

I’d heard about Docker a couple of months ago (their github repo is on fire!) and actually met up with a couple of their guys at Monktoberfest. We’ve been playing around with Docker at CloudSpokes for a number possible scenarios and that got me thinking: wouldn’t it be great if you could use Docker for Force.com development? You could develop locally, deploy the container to a sandbox for testing and then finally deploy it to production once it’s ready for primetime. This would be soooo much easier and more efficient than using change sets or ANT.

Docker has an index of community runtimes so that you can browse and find Docker container images. I know it’s a lot of work, but in theory, Salesforce could push a container with a stripped down version of Force.com with perhaps just what is required to write Apex and Visualforce. Since most of everything on Force.com is Java maybe include some additional jars for workflow, validation, running tests, etc. I know there are A LOT of technical hurdles to jump but this would be a boon to development on Force.com. No longer would you be tied to the internet to write code and test.

I’ve created this Idea so please go vote it up if you think this would be a good feature. You know it would be.

VN:F [1.9.22_1171]
Rating: 8.3/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: +4 (from 4 votes)

Categories: Salesforce

1 Comment

What? Use Force.com to Build an ESB?

October 17th, 2013

I spent the better part of two days early this month hanging out with Pat Patterson at the Monktoberfest conference talking about beer, technology and kids. If you don’t know Pat Patterson, I highly encourage you to find him at Dreamforce this year (you are going right?) and go introduce yourself to him. It’s highly improbably that you’ll ever find a nicer guy.

Anyway, over a glass of spicy South African mead, we professed our love for the Force.com Streaming API and threw out examples on how it is being used. If you are not familiar with the Streaming API, it’s basically a pub/sub model using the Bayeux protocol and CometD that allows you to “push” changes to Salesforce data that match a SOQL query (i.e., PushTopic) you define to external applications. So instead of having an external application that polls for changes to records in Salesforce, your application can “listen” for messages on a specific channel. We use the Streaming API extensively at CloudSpokes and it’s quite magical.

However, the PushTopic only sends messages concerning records that are created, updated, deleted, or undeleted. If you want to send generic messages, you have to set up another custom object, insert your message and then publish those messages. This works but it’s somewhat of a chore.

During our conversation Pat dropped a bombshell with “There’s a Generic Streaming pilot with Winter ’14 where you can send custom event notifications that are not tied to Salesforce data changes. You can essentially implement your own ESB.” (BTW… he said this with a slight slur as we’d been sampling beer most of the night). I was so excited about the possibilities that I immediately bought Pat a (free) beer!

So if you want to know more about the Generic Streaming pilot, check out page 284 of the release notes.

Side note: I’m still trying to get Salesforce to implement my Apex Queue idea. If you like it, vote it up here.

VN:F [1.9.22_1171]
Rating: 7.8/10 (4 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Categories: Salesforce

No Comments

Chatter for Apex Code Examples

October 3rd, 2013

At CloudSpokes.com we wrap a lot of the challenge process functionality into Chatter. So when we started to add more functionality to our site and org we naturally wanted to leverage the new Chatter in Apex functionality. However, it was a little more difficult that I anticipated. Chatter in Apex is a collection of Apex classes in the ConnectApi namespace that allows you to develop native, social Force.com applications. Perhaps I’m dense and a slow learner, but the docs and available recipes make it even more confusing. I just wanted an easy “hello chatter” application to get started.

So after getting some code up and running in production, I thought I’d publish some simple code to get people started. Disclaimer: this is not production code and is for demo only. However, you should be able to drop it in your sandbox and get going. The code has the functionality to make a simple text post, a post with a URL, a post mentioning another user and return a news feed. The code is also available at this gist for easy reading.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public with sharing class ChatterUtils {
 
  // makes a simple chatter text post to the specified user from the running user 
  public static void simpleTextPost(Id userId, String postText) { 
 
    ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;
 
    ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
    messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
 
    // add the text segment
    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    textSegment.text = postText;
    messageInput.messageSegments.add(textSegment);
 
    ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
    feedItemInput.body = messageInput;
 
    // post it
    ConnectApi.ChatterFeeds.postFeedItem(null, feedType, userId, feedItemInput, null);  
 
  }     
 
  // makes a chatter post with some text and a link
  public static void simpleLinkPost(Id userId, String postText, String url, String urlName) {    
 
    ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
    feedItemInput.body = new ConnectApi.MessageBodyInput();
 
    // add the text segment
    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    feedItemInput.body.messageSegments = new List<ConnectApi.MessageSegmentInput>();
    textSegment.text = postText;
    feedItemInput.body.messageSegments.add(textSegment);
 
    // add the attachment
    ConnectApi.LinkAttachmentInput linkIn = new ConnectApi.LinkAttachmentInput();
    linkIn.urlName = urlName;
    linkIn.url = url;
    feedItemInput.attachment = linkIn;
 
    // post it!
    ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.News, userId, feedItemInput, null);
 
  }   
 
  // makes a simple chatter text post to the specified user from the running user 
  public static void mentionTextPost(Id userId, Id userToMentionId, String postText) { 
 
    ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
    messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
 
    // add some text before the mention
    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    textSegment.text = 'Hey ';
    messageInput.messageSegments.add(textSegment);
 
    // add the mention
    ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();
    mentionSegment.id = userToMentionId;
    messageInput.messageSegments.add(mentionSegment);
 
    // add the text that was passed
    textSegment = new ConnectApi.TextSegmentInput();
    textSegment.text = postText;
    messageInput.messageSegments.add(textSegment);
 
    ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
    input.body = messageInput;
 
    // post it
    ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.UserProfile, userId, input, null);
 
  }     
 
  // pass the user's id or 'me' to get current running user's news 
  public static ConnectApi.FeedItemPage getNewsFeed(String userId) { 
    return ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null, ConnectApi.FeedType.News, userId);
  }      
 
}
VN:F [1.9.22_1171]
Rating: 8.6/10 (7 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Categories: Salesforce

No Comments

Debug Force.com REST Calls with Runscope

September 19th, 2013

I love APIs. I love to build them, cURL them, read their source code and talk about them. One of the aspects that I haven’t loved so much is debugging them. That is until I found Runscope. We’ve been using the service for a couple of months and it’s made debugging, testing and/or inspecting APIs sooo much easier. Of course Runscope works for all languages and essentially any REST API but we’ve found it especially helpful to build, test and debug Force.com REST calls.

Runscope was co-founded by John Sheehan who also loves APIs. I’ve know John since his Twilio days and he’s done an awesome with Runscope. The interface is very clean and service is intuitive and easy to use. If you are interested in APIs, you should subscribe to his API Digest newsletter.

Check out the video below on how to use Runscope with your Force.com REST APIs but in a nutshell here’s how it works. It’s a pretty simple process:

  1. Sign up for a free Runscope account
  2. Use the Runscope URL for the REST calls in your application to Force.com. For instance, your calls to http://cs8.salesforce.com will look something like http://cs8-salesforce-com-g0aderfwxe.runscope.net
  3. Once requests are captured, view your calls to Force.com in detail with the Traffic Inspector. Complete request and response data (URL, querystring parameters, form data, status, etc.) is available. There’s also a sweet little inspector where you can compare the deltas of two different calls!
  4. You can also create a shareable link to give to someone else to send, view, and comment on any of your API calls.

If you sign up for the paid version, you can use their Passageway service which allows you and your team to temporarily share your local development web server with others via a public URL. You can then of course run requests for localhost through Runscope and inspect traffic. Brillant!

VN:F [1.9.22_1171]
Rating: 10.0/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Categories: Salesforce

No Comments

The ‘Real’ Reasons Appirio Bought TopCoder

September 18th, 2013

Yesterday, we announced that Appirio has acquired TopCoder, which, when combined with CloudSpokes, will become the world’s largest professional development and design community with nearly 600,000 members! That’s more developers than Accenture, Deloitte and Infosys combined!

Now, if you want to read the “corporate-speak” on the acquisition, you can check out our official press release or Narinder has a great post on the Appirio blog. However, I don’t work with marketing any longer (apparently I had a habit of tweeting prematurely) so I’m going to explain what I think it means to the developer community and customers.

Match Made in Heaven the Cloud
The CloudSpokes and TopCoder communities are a great fit and compliment one another nicely. CloudSpokes members are very strong in cloud technologies, APIs and mobile while TopCoders excel in design, algorithm and analytics. We envision many members expanding their skill sets by competing in new areas afforded by the merger of the two platforms.

More Opportunities to Compete, Learn and Make Money!
The acquisition will provide members of both developer communities with dramatically more opportunities to earn money while showcasing their respective skills and capabilities. Both companies represent marquee clients such as Google, Facebook, NASA, Salesforce.com, etc. and we’ve seen an instant uptick in inbound sponsor activity. This only means more challenges, more learning and more prize money for everyone regardless of their talents.

TopCoder Open
We’ve been tossing around the idea for a couple of years now of doing a “mega-hackathon” where members compete to earn spots at the event. However, organizing an event like this is a daunting task for a small team. We are glad to announce that we will now be taking part in the TopCoder Open (TCO), a world-wide programming and designing tournament. It’s kind of a crazy event so take a peek at the video below or search for “TopCoder Open” on Youtube. As a part of our investment, CloudSpokes will add an additional track at the TopCoder Open happening November 10-14, 2013, for cloud development, as well as increases in prize money. CloudSpokes members should start receiving invites in the next few days. It’s gonna be absolutely nuts!

Educational Opportunities
At CloudSpokes we love learning new “things” and, of course, so do our members. We’ve sponsored free weekends at CodeSchool, written a large number of tutorials and launched a ton of “getting started” challenges to help member “learn more stuff”. We plan on making education a core foundation of the community. I love to teach and explain things so there might be something on the horizon for me (hint, hint).

Better Developer Profiles
I have to admit that we’ve not done such a great job at profiles and badges at CloudSpokes. We’ve wanted to put stuff into place for awhile now but we’ve been waiting on some “developments”. TopCoder has some really cool profiles data (check out this sample profile) and we plan on tapping into that as well as adding a little “more stuff”. We’ve heard stories of a number of CloudSpokes members being offered jobs based upon the skills and experience obtained while competing in challenges. We’d like to make CloudSpokes member profiles portable so that you can proudly display yours anywhere you’d like.

“Soup to Nuts” Development
For customers, the combination of TopCoder and CloudSpokes gives us the technology, platform and community to create an “uber” cloud services provider. Need a custom design for your iOS app? We can do that. Need a killer algorithm for your Node.js app on Heroku? We can do that. Need a super-slick HTML/CSS layout for your Force.com Sites application? We can do that. Need some analytics skills for your Google BigQuery project? We can do that. I’d list all of the things we can do but it’s tl;dr. The point is, virtually every skillset that you need for application development you can find in our community. The best. The brightest.

500,00 New Force.com Developers!
I eat, sleep and breath the Force.com platform every day. I love it (most of the time <g>). My goal is to get a significant number of our new TopCoder members developing on Force.com. Not sure if you know this but the platform is in need of more developers. I attended the SF Force.com Meetup last month and no less than 4 companies stood up and announced that they were hiring developers. I chimed up and ask if there was anyone in the room that was not hiring. Not a peep from anyone.

So there you go. My “real” reasons why we acquired TopCoder. Just to boil it down to one reason: it’s gonna be #superfrickinawesome for everyone.

VN:F [1.9.22_1171]
Rating: 8.7/10 (10 votes cast)
VN:F [1.9.22_1171]
Rating: +3 (from 3 votes)

Categories: Appirio, CloudSpokes

No Comments

Announcing the Force.com & Heroku Weekly Newsletter

September 10th, 2013

I’m been a fan of the Ruby, JavaScript, Node.js and Postres weekly newsletters and just realized that there is not one for Force.com and Heroku. So I decided to blatantly rip off the idea and start one! The goal is to curate articles that I think might be interesting to Force.com and Heroku developers and deliver it every Thursday for your reading enjoyment.

Go ahead and sign up while you are thinking about it. I’ll start sending out issues the first week of October to give people time to subscribe.

I’ve set up a Twitter account (@forceweekly) and am looking to get a logo designed and perhaps a new WordPress theme.

As I stated, I will be curating articles for the newsletter but if you have any links you would like to include, please send them to me and I’ll take a look at them. I’m not sure the best way to collect these (spreadsheet, twitter hashtag, form, etc.) so perhaps leave a comment with your suggestions.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Categories: Heroku, Salesforce

No Comments

Recap 2013 Salesforce MVP Summit

August 30th, 2013

I’m sitting in the Atlanta airport on my redeye flight home trying to catch my breath from the excitement of the last 48 hours. I’m returning from the 2013 Salesforce MVP Summit and struggling to capture all of the thoughts and ideas swirling around in my head. Salesforce flew all 75 or so MVPs out to San Francisco to provide us with an extremely confidential roadmap of their next 3 releases. They wanted our feedback as much as we wanted to hear about what is coming down the road.

So what can I tell you about features coming to the platform in the next 3 releases? Unfortunately, nothing. Wish I could because they are #awesome but I can’t. Sorry. We were sworn to secrecy and a Facebook and Twitter embargo is in place. There were threats of yanking out finger nails and first born children being surrendered. This led to some great tweets such as:

Why was this Summit so awesome? Because Salesforce honestly values the MVP community. They made key members from their senior management and product teams available to us for the entire day. There was an extremely honest and frank discussion (both ways) on what is great about Salesforce.com and where it needs improvement. The conversation got heated at times as everyone is passionate about the platform and only wants the best for it. I made the comment to Erica Kuhl that I think Salesforce.com got as much out of this meeting as the MVPs did. Honestly, Salesforce.com should be listening to us. We are dedicated, hardworking bunch of ISVs and consultants (there are 8 MVPs alone from Appirio!) dealing with customers every day and we can provide direct feedback on what we see in the field. Parker Harris made the comment that he didn’t want us to tell him how great everything is. He wanted to honestly know where Salesforce.com sucks. This was remarkable. I used to do SAP consulting and good luck finding anyone at Waldorf to listen to you let alone to provide you with information. Hell is still fairly warm I suspect.

First of all, Erica Kuhl and Matt Brown who run the MVP program did a fantastic job! Everything was well planned and thought out. It was great once again seeing the friends I’d made over the last 3-4 years in the community. Sure, you can stay in touch via email, twitter and facebook but nothing beats getting people together in one place from all over the globe with a common cause. It was an absolute blast just hanging out with everyone and meeting the new MVPs!

Erica and Matt put together a great mix of speakers. Each team presented their internal roadmap for the next three releases, elaborated as much as the safe harbor allowed them and always took questions. We had presentations from Mike Rosenbaum (Executive Vice President Platform) and Alex Dayon (President, Applications and Platform) on the platform in general (mobile, aura and canvas are going to be big!), Sales and Service Clouds (kick ass new stuff coming out!), Trust and Security with an awesome demo from Chuck Mortimore (this new stuff will blow your mind!), Dreamforce events (the app this year is sweet!) and of course Support. Charles Warren & Dan Darcy’s UI team was the star of the show with their workflow demo that blew people away. Throughout the day there were spontaneous shouts of “OMG”, audible gasps, clapping, standing ovations and comments like “this will change my life!”. At one point I thought Miley Cyrus was going to pop out and start twerking but it was Sassy instead making an appearance. Crazy day!

Parker Harris and Peter Coffee were there from sun up to sun down with us and everyone was highly approachable. I had the opportunity to have lunch with Peter Coffee and spent about 30 minutes talking with Parker. Both of them are super cool, regular guys. I confirmed that Parker did receive the copy of my Salesforce Handbook that I sent him. I assume it’s sitting prominently on his desk or bookshelf as a prize possession! (That’s how I picture it in my mind at least.) I also had an extremely long one-on-one conversation with Paul McNamara (VP of Platform Products) where we picked each other’s brain about the platform. I really like this guy. I also spent about 20 minutes with Steven Tamm (CTO) just rattling off features that I wanted to see on the platform. He had great feedback for each one of my ideas like, “it’s coming…. we don’t do a good job on that…. on the roadmap…. coming but harder than it looks…. done! …. done!” I absolutely love Steven as he’s no bull and tells it like it is… good, bad or ugly. Apparently the guy’s got some mad tech skillz as well as he still writes production code.

Other notables that were there most of the day included Shawna Wolverton (Senior Director, Platform Product Management) aka “the person that gets $h!t done at Salesforce”, Alex Toussaint (Sr. Director Product Management) who is ALWAYS working on fun new stuff, Taggert Matthiesen (Senior Director, Analytics) former Apex and Tooling API PM that is now heading up some mind blowing stuff with Analytics (his demo totally killed … just wait for it to come out!) and of course Dan Darcy who now leads the UI team. We were lucky to have Dan there as he was able to provide Taggert with some guidance on how to drive a demo and adjust his screen resolution for optimal viewing.

Appirio Salesforce & Force.com MVPs

I can’t say how thrilled and lucky I am to be part of the Salesforce community! I’m looking forward to next year’s MVP Summit and meeting all of the new faces from the community! BTW, if you haven’t purchased your ticket for Dreamforce yet, DO IT NOW! It’s gonna be #superfrickinawesome.

VN:F [1.9.22_1171]
Rating: 8.9/10 (15 votes cast)
VN:F [1.9.22_1171]
Rating: +7 (from 7 votes)

Categories: Appirio, Salesforce

1 Comment

First Look – Salesforce.com Aura UI Framework

August 13th, 2013

Fun stuff coming out of Salesforce as we ramp up to Dreamforce! I had the opportunity to sit in on the “Intro to Aura” webinar a few hours ago and I thought I would blog on some key points that I came away with after the whirlwind hour. First of all this is a major initiative for Salesforce.com as it was hosted by Andrew Waite, Josh Kaplan and Doug Chasman (tech lead for aura and one of the Visualforce architects). The project is very early and probably will not even be in public beta till Spring 14 (safe harbor).

First of all what is Aura and why is it so significant? Aura is a UI framework for developing dynamic web apps for mobile and desktop devices (with or without Force.com), while providing a scalable long-lived lifecycle to support building apps engineered for growth. Probably one of the most significant factors is that the project is entirely open source. This is a very big accomplishment for Salesforce.com as I believe it’s the first time they will accept external contributions and roll them back into a fully supported Salesforce product. They are really reaching out to the developer community for input and support to make this a success for all of us.

Some key features of aura include:

  1. Tag-based layout & component definition
  2. Encapsulated UI development with a strongly typed event model
  3. Object-oriented programming behaviors (extends, implements, abstract)
  4. Encapsulated bundles with models, controllers, CSS, static resources and markup
  5. Integrated functional and performance testing (did you expect any less?)
  6. Mobile, mobile and mobile-ready

There are two parts of aura, an open-source package and Force.com package. The open-source package is available now on github and you can start playing with an early version of it. Right now the core framework is server side Java but there are adapters for essentially any JVM-based language (Heroku FTW!). Languages such as Node.js and .NET will be a little tougher to implement but Doug seems very open to talking about a road map. There is also an Eclipse plugin but I haven’t found reference to it yet.

The Force.com package will have all capabilities of the open source package but will on course be in Apex. Component bundles will saved to the Force.com database and there will be special Salesforce metadata-aware components such as Chatter feeds, inputField and outputFIeld and recordLayout (detail / edit), etc. There will also be some new standard and custom components that can be embedded in standard page layouts, the developer console and even override standard components.

Will aura replace Visualforce tag? No. There is a Visualforce adapter so aura tags will work in Visualforce pages; apparently you can pick and choose which components you use during development. There are also some cool developer tools including enhancements to the Developer Console, plans for integration with the Force.com IDE and the Tooling/Metadata APIs.

Components can be developed independently and dropped into bundles. They are even extensible for maximum reuse. Here’s a component from the sample application to give you a quick look:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<aura:component extensible="true">
    <aura:attribute name="desc" type="Aura.Component[]"/>
    <aura:attribute name="onclick" type="Aura.Action"/>
    <aura:attribute name="left" type="Aura.Component[]"/>
    <aura:attribute name="right" type="Aura.Component[]"/>
    <li onclick="{!v.onclick}">
        <ui:block>
           <aura:set attribute="left">{!v.left}</aura:set>
            <aura:set attribute="right">{!v.right}</aura:set>
            <h2 class="subject truncate">{!v.body}</h2>
        </ui:block>
        <aura:if isTrue="{!v.desc != null}">
            <p class="desc truncate">{!v.desc}</p>
        </aura:if>
    </li>
</aura:component>

Aura has been in development for a number of years (it was almost released as “lumen” last August) and is being used for Salesforce Touch, Chatter, Force.com App Builder, Site.com Component Framework and Opportunity Splits (Sales Cloud). Andrew stated they they needed to develop their own framework as opposed to using an existing one due to the multi-tenent nature of the Force.com platform. Makes sense.

So how can you get started? You can certainly take a look at the aura project on github but I’d highly recommend forking the aura-note sample application as it is loaded with some great code to get you started. Also, go ahead and submit issues and ideas as Salesforce.com is very receptive. I submitted an issue last week and Doug had it fixed in no time.

VN:F [1.9.22_1171]
Rating: 9.3/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Categories: Salesforce

No Comments

Log Force.com Events & Exceptions

July 24th, 2013

Logging in Force.com can be somewhat of a challenge. Since there’s no log file you can write to, we need to develop another mechanism to record events and exceptions that we can inspect later. Sending emails with exceptions information is fine, but it may become overwhelming. So let’s implement a Custom Object called Log__c that we can dump events and exception info into. We can then run reports, implement workflow, write triggers and do all kinds of cool stuff for this object. We’ve been using this methodology (sparingly for certain situations) for a couple of years at CloudSpokes and it’s worked quite well for us.

Disclaimer: This may not work for all use cases as exceptions will cause all commits to rollback, including your log inserts. Another route may be to insert these log records asynchronously (using @future) but you need to ensure that this method is not being called from another asynchronous method. Also you may bump into some governor limits so check the docs for specifics.

So, first create a Custom Object (Log__c) to hold all of your entries.

I added a lookup relationship to our Challenge object as I’m just recording events from these records. The Class__c field simply allows me to record from which Apex class the event or exception occurred. Message__c is the actual message being logged while Priority__c is essentially the severity of the message. You can pass values such as INFO, DEBUG, WARNING, ERROR or FATAL and then write workflow notifications based upon this severity.

So here’s a little helper class that you can call from your Apex code to make logging easier. You essentially pass it the info you want to log and it will do the rest for you. You may want to add some exception and bulk handling. In our case at CloudSpokes we ensure that these transactions are not occurring in bulk. You may want to write a log method that accepts an Array of LogMessages or something similar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class Logger {
 
  public static String INFO = 'INFO';
  public static String DEBUG = 'DEBUG';
  public static String WARNING = 'WARNING';
  public static String ERROR = 'ERROR';
  public static String FATAL = 'FATAL';
 
  // insert a generic log entry 
  public static void log(String priority, String className, String message) { 
    insert (new Log__c(priority__c=priority,class__c=className,
      message__c=message));
  }
 
  // insert a log entry for a specific challenge record
  public static void log(String priority, String className, String message, ID challengeId) { 
    insert (new Log__c(priority__c=priority,class__c=className,
      message__c=message,challenge__c=challengeId));
  }
 
  // test method
  public static testMethod void testLogger() {
    Test.startTest();
    Logger.log(Logger.INFO, 'TestClassName', 'My Test Message');
    Test.stopTest();
    System.assertEquals(1,[select count() from Log__c where class__c = 'TestClassName']);
    // make sure the log info was written correctly
    Log__c log = [select Priority__c, Class__c, Message__c  from Log__c where class__c = 'TestClassName'];
    System.assertEquals(Logger.INFO,log.Priority__c);
    System.assertEquals('TestClassName',log.Class__c);
    System.assertEquals('My Test Message',log.Message__c);
  }
 
}

So now in your code you can do something like the following to log an event:

1
2
3
4
5
6
public virtual Decimal scoreParticipant(String membername) { 
  Logger.log(Logger.INFO, 'ChallengeBase', 
    'Scoring participant: ' + membername, 
    this.challengeId);
  // keep performing awesome Apex code
}
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Categories: Salesforce

No Comments

Feed

http://blog.jeffdouglas.com /