Ever wondered what a punchcard looked like?

I was reading a book the other day about computer history and so I thought it would be fun to see an actual example of what a punchcard looked like and how they worked. As an homage to our forefathers I decided to mix some old and new. Below you've find some Apex written on a DEC-029 punchcard.

DEC-029 Punchcard with Apex by @larsnielKind of cool. Even better though, go here to create your own. And you thought it wasn't fun to use the Developer Console to debug your code! Look at how far we've come...



SOQL Query Plan Tool

Salesforce added the Query Plan tool as part of Summer 14'. It's actually a lot of fun for those of us that come from a SQL background and love to get our hands in the guts behind the scenes. It is also really helpful and interesting if you don't like guts. In this article, we're just going to ease into things and show you how to launch the Query Plan Tool and then in Part II we'll go into more detail about what it all means. Anytime you write a SOQL statement, run a report or even just view a record in Salesforce - the underlying framework (i.e. the database layer) has to come up with a battle plan on how to get the data.

Click to read more ...


What is the Lightening process Builder?

With Spring 15' comes the release of the highly anticipated Lighting Process Builder. For those not familar, it is a really slick way to graphically draw out automated tasks inside Salesforce. Salesforce has been working really hard over the last couple of years to give everyone (technical and non-technical) the ability to make productvity advancements with Salesforce. 

Before Lightening Proces Builder, administrators and developers would have used a combination of workflow rules and apex to build out automated tasks and processes. The beauty here is that you can do this in one place rather the than creating multiple rules. In addition, more actions are available to you than a traditional workflow.

The Lightening Process builder allows you to create a record and or post to chatter


See a sample of the user interface below, it's extremely inuative.


The Lightenging Process Builder doesn't fully reaplce validation rules and approval processes; however, it sure does just about all the same things in a very easy to use way. The only real exception that I've come accross is the need for Outbound Messages.


SOQL Offset

Hi guys, sorry - it's been a while. Lots going on lately but I wanted to catch everyone up on something I found handy the other day - the OFFSET clause on a SOQL query. It was added as part of API 24.

OFFSET can be used as an efficient way to handle large result sets


Use Case

 You want to sit down with your significant other and watch a marathon of Walking Dead. I'm talking all the episodes from the pilot to the most recent episode. There is just one catch - you watched the first four epidoes last weekend and you want to skip straight to episode 5 "Wildfire" and you're using SOQL. Okay, I realize this is far fetched but we've made it this far so let's stay with it a little longer and see how Offset can help us write a SOQL statement that will help us out...

Offset is like saying "give me the first X records but skip some records before you start the counter"


Select, Id, Name, Synopsis, OriginalAirDate from Walking_Dead__c OrderBy OriginalAirDate Limit 100 Offset 4

This will give you records 5 through 100.

Best Practices

  • Use an ORDER BY clause when you use OFFSET to keep your results consistent. The row order of a result set that has no ORDER BY clause isn't going to be stable.
  • It's also smart to use a LIMIT clause in combination


Things to keep in mind with SOQL OFFSET

  1. The maximum offset is 2,000 rows (as of Spring 15'). If you try to pass in a number larger than 2,000, you'll get a nice little NUMBER_OUTSIDE_VALID_RANGE  in return.
  2. Offset is intended to used as part of a top-level query. It's not meant (and not allowed) in most sub-queries. If you try to add an Offset in a sub-query you will often get a  MALFORMED_QUERY.
  3. Offsets ARE NOT A REPLACEMENT for using queryMore()



SOQL Using Scope (new in Winter 15')

SOQL query filtering with the new USING SCOPE clause

One really useful thing added in SOQL with the Winter 15' release is the ability to a Scope clause to a SOQL query. A common task we all find ourselves with at various times is the need to grab a group of leads or accounts for example and perform an action on them. More specifically if you use territories, you may need to get a list of all the accounts in Territory X and do something with them.

Prior to Scope, you would attack the problem backward. i.e. what makes up Territory X (who is in it, what is the territory region etc etc.) You would then build a query around those parameters. With scope there is now an easier option. Scope takes one enumeration values { Everything, Mine, My_Territory, My_Team_Territory or Team}

Example (grab all the accounts that belong to you)


Example (grab all the accounts that are in your territory) 

SELECT Id FROM Account USING SCOPE My_Territory 


Note: This also works on Customer Objects


Salesforce Dataloader Heap Space Exception

If you are trying to upload and download large volumes of information using the Salesforce Dataloader you might run into this error. "Java Heap Space" from the Data Loader UI version 21.0 onwards This is common especially if what you are loading is large attachments (PDFs, Powerpoints etc). The Salesforce Dataloader is a Java application that runs on the local Java Virtual Machine (JVM). The heap size is essentially how much memory is allocated to the application while it runs. Starting with version 21 of the Salesforce Dataloader the heap size is more restrictive than in past versions. There are some quick fixes to get your around this issue.

Click to read more ...


Using An Apex Map with a List of sObjects

The other day I found this handy. It's a slight twist on something I found in the developer documentation. Ultimately I wanted to quickly compare some Account IDs and see if any from list A were in list B and if so, perform an action on the Accounts in list B. I decided that a map would be good for this task.

First, a quick review of what a Map is. A map is essential a key/value pair list. Here is the textbook definition:

A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. - Salesforce Developer Documentation

A Map is perfect for this particluar task because Salesforce object IDs are unique just like the key in a Map. There is only ever going to be one.  

Below is a snippet of an "auto" populated map of the Accounts I was interested in.


List<Account> listAccountsWithSupport = [select Id,Name from Account where HasPaidSupport__c =  true];
Map<Id, Account> mapAccountsWithSupport = new Map<Id, Account>(listAccountsWithSupport);

I can now quickly compare the Accounts I have in List A with this second set of Accounts stored in a map. Both A & B could actually be maps but the method I'm working with in the legacy code already returns a List for the Accounts in pile A.

for(Account a: listAccountA){

//check to see if the current account in list A matches any in our Map (which is pile B)

  if(mapAccountsWithSupport.containsKey(a.Id)) {

      a.HasPaidSupport__c = true; //perform the desired action

/*we can also perform actions on any of the accounts in the Map if we want by using a.Id to find a specifc Account. Below will return the actual Account object based on the  key "id" if it finds one. At this point you could perform an action if you wanted. */

     Account tmpAccount = m.get(a.Id);



update listAccountA; //make sure to call any updates outside the loop :)



Three Common Apex Coding Topics

If you're an admin of a big Salesforce org, then you probably had some users complain about unfriendly errors. If your Salesforce org is in any way customized then those errors are likely related to performance issues in the custom Apex code. Although custom Apex code can be powerful, it can sometimes hinder the overall performance of your Salesforce org. Today, I'm going to introduce three changes you can make in Apex Code that will improve the performance of your Salesforce:


Enhance Validation and Workflow Rules:

One example of the errors your users might get is one that includes FIELD_CUSTOM_VALIDATION_EXCEPTION. This error usually means that you have a scheduled batch that inserts/updates records without fulfilling a Validation Rule(s). Here are a few areas you can improve performance:

  • If you have a batch class, make the class calls a DML operation and that opt_allOrNone is set to False. This will allow the rest of the operation to still succeed even if the record fails.
  • Workflow Rules are most helpful in preventing duplicate records. If you have a lot of Workflow Rules in your org, you can cut down unnecessary processes by deactivating the Workflow and improving the Trigger to do the Workflow Rule'sjob.
  • Review Validation Rules with management and make sure they are necessary to fulfill business logic. Having too many validation rules and required fields can cause unit tests to fail, which will then prevent you from deploying a change set.

Increase Field Length:

If, for example, you have a Trigger that populates values larger than the field length, then you'll most likely get a STRING_TOO_LONG error message. One thing you can do here is to increase the Field Length; it is better to have a large value than getting an error message.


Rectify API Limits:

If your org has a lot of integrations with third party apps and that those integrations are used frequently, your users might then see a "REQUEST_LIMIT_EXCEEDED" error. There's no ideal solution to reducing API usage, but one thing you can do is to evaluate the current API usage in your org (SetupAdministration SetupCompany ProfileCompany Information) and figure out a way to reduce and disperse the number of API calls.


It is always a good idea to periodically review the current custom Apex Code you have in your org with management and stakeholders. Making these changes will not only cut down the number of errors your users encounter, but will help improve the performance and the overall user-experience in your Salesforce.

Jan032014 Tip: Freeze Users

When administering Salesforce, you can at times run into scenarios where a particular users’s account should no longer have access. An example of that is when you have reason to believe that a user’s account has been compromised or someone has just left the company and you want to prevent them from logging in. Normally you would just disable the user; however, if the user is part of a custom heirachary field - there are more steps invovled. A nice solution in the meantime us to just use the "Freeze" function. 

To freeze a user in your org, go to Your NameSetupManage UsersUsers. Find and click the user and then click “Freeze” to freeze the account. 

salesforce freeze user
After the user is frozen - the Freeze button changes to an Unfreeze button which performs (well, you get the idea).
Note: When you freeze a user, it does not free up a user license. In order to actually free up a licnense you have to perform an actual deactivation of the user.