The Dark Art of CPU Benchmarking

Benchmarking in Salesforce is an important skill to learn, especially since Salesforce introduced the CPU timeout of ten seconds in the Winter ’14 release. If your code is inefficient, you may start to see exceptions thrown if processing the logic takes longer than the allotted ten seconds (sixty seconds when running asynchronously). Furthermore, other packages running in your Salesforce instance directly impacts all code and declarative functionality – unlike most Salesforce limits, the CPU timeout limit is not unique per namespace. (Also – benchmarking can be fun!)

I was a co-presenter on the topic of CPU benchmarking with Dan Appleman at this year’s Dreamforce conference. Missed the presentation? It was recorded! Check it out below:

The sample code used in the presentation can be found on GitHub at https://github.com/robertbwatson/df16-benchmarking. For more information on CPU benchmarking, I encourage you to reference Chapter 3 in Advanced Apex, or search for CPU benchmarking on SearchTheForce.

— Robert

Salesforce TrailheaDX Campfire Story

In June, I had the opportunity to attend Salesforce’s TrailheaDX conference. In one of the sessions, I gave a quick 5 minute “campfire” story. Here it is, in written form!

Attending Dreamforce this year? Join me on Tuesday, October 4th as a I teach you about the Dark Art of CPU Benchmarking with Dan Appleman. Look out for a recap post here shortly thereafter!

TrailheaDX Campfire Story

Not so very long ago, I worked on a managed package that had thousands of unit tests. Thousands! To care about ensuring that *all* code is functioning properly in such a large product is pretty cool, right?

Well, there was a problem. A few, actually.

If you wanted to run these unit tests in one of the development orgs, go get a cup of coffee. Actually, you might as well go get an entire pot because they were taking over an hour to run! How could they be taking so long?

The team set out on a discovery and realized that updating the Apex Test Execution options and unchecking the “Disable Parallel Apex Testing” setting brought the time down from over an hour to 15-20 minutes. We found a solution – what a relief!

However, our journey was not yet done. Imagine you’re out walking in the sweltering hot forest – your water is almost gone, there are several blisters on your feet – and you spot your final destination out in the distance. So you keep walking, getting ecstatic that this will be all over soon… but you’ve been fooled. While your final destination may appear to be close, you soon realize there are several more hills to climb and fallen trees and rocks to maneuver around.

When running the tests asynchronously, many tests would fail due to row locking issues. It was never the same ones, and simply ignoring the failures was not an option because it wasn’t sufficient to say “oh, well they just failed because of row locking, but we know the actual unit test does really work.” So now we had to figure out which ones failed and select those to re-run again. And sometimes some of those would fail, and we’d have to re-run the ones that failed a second time.

One day, a developer stumbled upon the Salesforce Winter ‘16 release notes and made an interesting discovery. If you run unit tests through the Developer Console instead of from the Apex Test Execution page, there’s an option to re-run the failed unit tests! This means that you don’t need to manually re-run the classes that failed. Even better, you can select to run only specific test methods within a given test class instead of running the entire class.

This was great news. Developers everywhere rejoiced. While running so many tests asynchronously still causes row locking issues, we had better tools to enable us to confirm they all worked as expected.

So, what can we learn from this? First and foremost, read the Salesforce Release Notes – you never know what gems you may find. But don’t worry about remembering everything (because you won’t). You can always go back and re-read them later when it is more relevant for you – Salesforce doesn’t remove previous release notes. And even better, you can navigate the Salesforce Developer Documentation by release version as well!

Switchin’ It Up

It’s time for some changes.

Wait – don’t worry! Not all changes are bad. In fact, I like to think this is a good change.

Buying my first house and getting engaged wasn’t enough adventure for one year. This past May, I accepted a senior software developer role at Full Circle Insights and decided to leave my position at NimbleUser, where I’d been working for the past four years. Among many other reasons, I am quite excited to be working in the same time zone as all of my coworkers once again. I’m happy for the new opportunity and thrilled that I get to continue contributing as a Salesforce developer.

So, how does change relate to this blog? Well, it’s time for a rebranding. Along with my new position, I am also itching to become more involved in the Salesforce community. One of the easiest ways to connect is to share my expertise, and I think this blog is a good place to start.

Over the next few weeks, I’ll be transitioning the web site to highlight only Salesforce and technology-related blog posts on the home page. There will be a separate page that will be a hodgepodge of all posts, personal and professional. Instead of posting every three or four months, I’m hoping this change will also motivate me to start blogging on a more regular and consistent schedule.

Let’s begin the new journey!

— Robert

2015: Laser Eyes & Expensive Purchases

I’m almost a month late this year, but it’s once again time to reflect back on another year of accomplishments and establish my 2016 goals.

While I didn’t do nearly as much traveling in 2015, it was still an adventurous year that included a trip to Hogwarts and a marriage engagement when Tym and I finally moved into our first house in December! (Yes, the house hunt is finally over.)

2015 Goals Reflection

In reviewing my 2015 goals, I’d say I exceeded most of my expectations from last year.

  • I have laser eyes now – I had Lasik eye surgery last March.
  • I participated in three half marathons. Though I didn’t race in any duathlons, that will definitely be a focus for 2016.
  • I haven’t yet earned my Salesforce Advanced Developer certification, but that’s primarily because Salesforce spent several months revamping the process and the exams were unavailable. I completed the final assignment and essay in November, and now I’m just waiting to receive the results.
  • I read another 10 books throughout the year, the same number as in 2014. I also wrote nearly 30,000 words of fiction. This was under my goal of 60,000 words, but I’m giving myself a bit of a break here since work and house buying both took up more of my summer and fall than anticipated.
  • I did not learn as much as I would have liked. This will also be a bigger focus in 2016.
  • I continued volunteering at the local food bank through most of 2015.
  • Not only did I research buying a house — I bought a house!

2016: The Harry Potter and the Cursed Child & Wedding Adventure

As always, many of my goals are staying similar to last year. But I have a few additional goals as well. With a trip planned in August to London to see Harry Potter and the Cursed Child and a wedding to plan for the fall, 2016 is shaping up to be another busy year.

My main goals…

1) Average 7 hours of sleep per night. This was an unwritten resolution for me in 2015. I’d like to make it more official and to continue the trend. Having a Microsoft Band has made me realize how little sleep I had been getting. My sleep has greatly improved over the past year, but it could still be better.

2) Continue learning. A repeat goal. I started watching a CrashCourse series last year (World History), but I haven’t finished. I’d also like to complete CrashCourse Psychology. And there are several SciShow episodes that have been in my “Watch Later” queue for years.

3) Keep focusing on half marathons, but also spend more time biking and swimming. As I mentioned previously, I raced in three half marathons last year but no duathlons. I’ve also done well at going to the gym regularly, but my bike did not get much use last year at all. I want to start swimming at the gym and to bike around the city more often. If possible, I would ideally start commuting to work this way (by biking… not by swimming).

4) Increase time spent reading & writing – read a book a month. I’ve been averaging 10 books a year. This year, I want to aim for one a month. Now that I have a longer commute to work, reading on the bus has been a great way to jumpstart my mornings.

Additionally, I’m going to aim for another 60,000 words of writing this year. If I’m being honest with myself, this will probably be the first goal that gets cut from the list.

5) Continue volunteering. I wasn’t originally going to put this on the list, but I need to pick this up again since volunteering at the food bank fell off my radar while I was dealing with the move and the Christmas holidays.

My list is shorter this year and definitely attainable. What are your goals this year?

Hoping for yet another great year,

— Robert

House Buying: Navigating A Crazy Market

In my annual goals post back in January, I wrote for one of my 2015 objectives:

“Start looking into what it takes to purchase a house or condo.”

I’ve made progress on all of my goals so far this year, but little did I know that I would go far and beyond exceeding this goal.

Well, sort of.

Not only have we’ve started to look into the house buying process, we dived head-first into the adventure back at the end of May. In the past four five months, we’ve 1) found a realtor, 2) found a bank, 3) walked through approximately 40 60 80 or more homes, and 4) conducted an estimate on a fixer-upper listing and pre-inspections on two others, and 5) put in an offer on three four different properties.

FOUR offers. You would think that after four very strong offers (alright, maybe only 2 or 3 were really strong), I would be the proud co-owner of my first home. But that is not true. The Seattle housing market is so fierce that I’ve heard multiple stories of people placing over a dozen offers and still not finding their dream home.

Thankfully, I’ve at least gotten something out of it: I’m learning the Seattle market. I know (relatively) where I want to live. I know my likes and dislikes, and I understand important things to consider when touring a house. Going through so many different scenarios has allowed me to see various aspects of the business, like submitting an offer with a renovation loan vs. traditional loan.

One Week.

If the house is priced correctly, that’s all the time you have to tour the home and assemble an offer.

The typical week looks something like this… Continue reading