Web services development on Salesforce

by Patrick Connelly posted on March 09, 2015

Several years ago, I wrote a blog post on developing web services on Salesforce. When helping someone in the IRC channel with web services, I realize that the article was outdated and does not follow some of the design patterns that I have learned after spending a lot of time with web services

What are Web Services?

Let’s start with a little background. Web services are Apex code that you expose out and can consume with either SOAP or REST. Typically this is used to expose complex business logic in an easily consumable way. For example, you could use a web service to combine together an account with all of it’s contacts and return them in a single call. In this article we will be covering SOAP endpoints, but most of the principles also apply to REST endpoints.


Storing Schema RecordTypeInfo in Apex

by Patrick Connelly posted on March 04, 2015

I was recently helping a friend with some Apex Controller work for a new VisualForce page, and ran across this error being displayed on the page.

Not serializable: Map<Id,Schema.RecordTypeInfo>

It was weird because it did not appear to be anywhere in the debug logs and it did not email her that an exception occurred anywhere.


Bitwise operations in Apex

by Patrick Connelly posted on February 17, 2015

A couple of days ago a friend of mine was asking about how to do bitwise math on Salesforce in Apex. I didn’t know how to do it on the platform so I decided to give it a shot.

NOTE: None of the topics covered here are specific to Apex or the Salesforce platform. These concepts extend to most languages. However, the code examples below have been tested and verified on the Salesforce platform.

What are bitwise operations?

Bitwise operations are operations that deal with numbers on a binary level. You see this type of operation mainly in lower level programing languages where you have limited resources and need to store lots of information in a small amount of space. For these examples we’ll be using the match details from DOTA 2 output. This allows for Valve to return a single number to represent lot of information.


Humblemug – My first node module

by Patrick Connelly posted on February 14, 2015

I have been working on migrating a site that I designed off of HTML with lots of javascript into a node.js app. The site has very little in the way of user interaction and mainly just displays dynamic data out to the users. This data is pulled from a number of sources but because it’s pulled client-side it’s terrible for SEO (I was young and should have known better).

One of the issues I encountered when migrating this site is that they have a gallery page that pulls data from a SmugMug album. When this site was originally written, SmugMug only had an XML based API and to make it so that JavaScript would play nice, I had to write a php wrapper that would pull down the XML and re-host it on the same domain. I sure as heck wasn’t going to tarnish my pretty little rewrite with PHP. So I tried to find a node module for SmugMug, and much to my surprise, couldn’t. And with that, Humblemug was born.

Humblemug

Humblemug is really quite simple. It makes the http requests and spits out the JSON that the SmugMug 1.3.0 API returns. Where Humblemug got interesting is that it’s my first package published out on npm. I’ve written modules for local apps, so I’m familiar with the structure, but I’ve never had to write something that others could use.

I followed the guide that Brent Ertz published and it went without a hitch. The module is really bare bones right now (I only added the couple of methods I needed) and has no testing (GASP!). I plan on adding testing soon and then adding some more functionality to it soon. Hopefully I figure out how I want to structure everything before I get too far and have to re-do it all.

So, if you have a need for SmugMug integration in node.js feel free to checkout my first module.

Download Humblemug


Mobile SDK 3.1 released

by Patrick Connelly posted on February 13, 2015

At the end of last year, Salesforce released the Mobile SDK 3.0 which added quite a few new features. Now, they’ve released the Mobile SDK 3.1 with some really nice new features. I have not had a chance to dive into the Mobile SDK prior to this release, but I think it’s made some great progress and should be something to give a try of.

Background on the Mobile SDK

Mobile SDK Unified Cross Platform Architecture

The mobile SDK is a great way to write native apps for iOS, Android or hybrid apps using a number of web frameworks.

What’s new?

The updated SDK includes:

  • A more consistent implementation for native and hybrid apps for iOS and Android
  • Full CRUD operations for both online and offline usage
  • CocoaPods for iOS
  • Library updates

What can I do with this?

The updated mobile SDK makes it even easier now to get started with Android Studio and Gradle now being fully supported for native apps. To get started, checkout the Mobile SDK wiki page for the learning path you want to take. You can also take a look at the Android, iOS or Hybrid sample apps to get started.

Read the full announcement


Salesforce Trailhead: New Modules

by Patrick Connelly posted on February 03, 2015

At the 2014 Dreamforce, Salesforce announced Trailhead, their new platform for learning all about the Salesforce platform, and I have to say it’s pretty great. Anytime someone asks me how they can get started with Salesforce, “Trailhead” is pretty much the first thing out of my mouth. Well that and the IRC channel.

It’s been a couple of months now since Trailhead was released and we’re finally getting new content, and a little bit of updated content for some of the older modules. In addition to these changes the platform seems to have gotten better about it’s error messages when you fail a challenge.


Fun with maps and sets

by Patrick Connelly posted on January 26, 2015

While working on Apex, I discovered an interesting behavior with Maps and the keySet method.

Problem

class TestData {
	public String data;

	public TestData() {}

	public TestData(String data) {
		this.data = data;
	}
}

Map<String, TestData> dataMap = new Map<String, TestData>{
	'foo' => new TestData('foo'),
	'bar' => new TestData('bar')
};

Set<String> keySet = dataMap.keySet();
System.debug(keySet.size()); // 2
System.debug(dataMap.size()); // 2

keySet.remove('foo');
System.debug(keySet.size()); // 1
System.debug(dataMap.size()); // 1

This code does not behave how you would think. If you remove an item from the keySet set it also removes it from the dataMap. What I believe to be happening here is that the keySet method is returning a reference to the key set of the dataMap.


Displaying Salesforce Test Status in screen using JSforce

by Patrick Connelly posted on September 29, 2014

This post will probably only be useful to one other person out there, but it was a fun exercise and thought I’d at least share my output.

One of the biggest challenges I have when running tests is that I will often forget they are running and leave them completed for a while before I go back and remember I ran them. This mainly happens when I’m running an entire class worth of tests and have 5-10 minutes to kill. When first learned about JSforce and it’s cli capability I was in love! So I set out to make it so that the current testing status is displayed inside of my screen session. At the end of it all this is what I came up with:

Screen status


Why developers should go to Dreamforce, and how you should prepare.

by Patrick Connelly posted on August 08, 2014

With Dreamforce just around the corner, it seems appropriate to do my list of reasons why developers should go to this conference. Over the past couple of years, Salesforce has really stepped up their game in bringing more to the conference for developers. So, why should you go to Dreamforce (or why should you send your developers)?

  • Networking – This is my top reason. Yes all of the ones below are great reasons, but this is the one I still use long after my first Dreamforce. You get the chance to meet so many other developers and they are the ones you can lean on long after Dreamforce has packed up. Try to find people near you that you can sync back up with afterwards to get more involved. And there are plenty of social events you can join that don’t require you to think and can get you some exercise, such as the Community 5k or the Streaking to Dreamforce
  • Hands-on development – There are lots of opportunities at Dreamforce to get your hands on code and have someone there to help you if you get stuck.
  • Best practices – If you want to learn if you’re doing your Salesforce development right, this is the place to figure it out. There are lots of talks that go over the best way to do development with everything from handling bulk data, testing and even deployments.
  • Reid Carlberg – Ok, so maybe not just Reid, but folks like Reid who do neat stuff with technology. In 2013 there was the Connected Device Lab and it was fantastic. It’s a great way to learn about the Internet of Things. I can only assume that this year it will be even better!

So, now that you know you’re going what should you do to get ready?

  • Register – This is pretty obvious right? Well, go ahead and do it now so you’ll be ready when it’s time to sign up for talks
  • Be ready to sign up – Once the session list goes up, you should be ready to jump in. The really good sessions fill up fast. I’d recommend following @salesforce and @salesforcedevs on twitter for the best chance to see when it’s time.
  • Ask questions – Get on Chatter/Twitter/ and ask questions if you have them. Dreamforce is huge and can be quite daunting if it's your first time. There are plenty of fantastic people out there that can help you out.

Intro to Apex: Auto converting leads in a trigger

by Patrick Connelly posted on July 23, 2014

Over the past couple of weeks I have seen several posts on the developer forums about writing a trigger to auto convert leads based on some criteria. Since this seems to be a pretty common topic, I thought I’d turn it into my first “Intro to Apex” blog post. In this post I am going to introduce a trigger that converts a lead and the test for this trigger. I am going then break down each line of the trigger and explain what it does and why it is there.

NOTE: This is a very basic trigger. If this were to be used in an environment where there was more than just this functionality in the trigger, I would classify this trigger to control the order of operations.