We’ve all been there, working away in Salesforce, when suddenly we get a plain white screen with some simple black text that stops us in our tracks – an error message. Something has gone wrong. Just like our LEGO® man below, panic can set in. Why are we getting this error? What did I do wrong? How do I fix this? Fear not, in this post we will go through how you can defend yourself against these errors properly.

Lego Figure in Despair

These errors can broadly speaking be placed into 3 groups:

Access Errors

When you see the words “insufficient privileges” then you should think about permissions and visibility. How has the user got to here and should they be able to get here? It could be an issue with sharing settings or profile permissions, but hopefully it is fairly easy to fix. The same applies for if you are told a record no longer exists – where did the link to it come from?

Code Errors

The phrase “attempt to de-reference a null object” fills many developer’s hearts with dread but these errors are pretty simple to handle. Other code errors may just need re-saving and compiling. The most difficult often involve a governor limit being exceeded such as “too many SOQL queries 101”. Whilst at first these errors are often mysterious, experience and some careful analysis normally makes them resolvable, and following best practices can often help you avoid them.

Internal Server Errors

As soon as you see the phrase “An internal server error has occurred” then you know you need to start thinking. What sets this type of error aside from all others is that it doesn’t really give you any clue as to what you have done to cause the issue. They can also occur from almost every part of the system. This type of error is also known as a GACK and is the focus of this post today.

What is a GACK?

Put simply, seeing a GACK is recognition from the Salesforce team that something has gone wrong that shouldn’t have and as the Salesforce team have stated

“What this means is that it’s not your fault. It’s ours. That’s why we apologize in that message. Sorry!”

The old blog post that quote comes from gives a bit of an overview of why GACKs occur and what the numbers mean (essentially identifiers for the error for the R&D team). The first thing you should do if you receive one of these errors is make sure it is repeat, raise a case with Salesforce support, and ask them to give you some information on what was causing the error. They should come back to you with some information, but depending on your level of support and the urgency of the issue, this may take some time. So what can you do in the meantime?

1. Roll Back and Inspect

If you get this error after making a change in your code, roll back the change to the previous version (either a good old undo but hopefully a git revert or something similar) and look at what you did. Check the documentation, are you doing something strange? Maybe looping through a not supported type in a standard component? Can you try and achieve the outcome in a different way? Can you do a smaller half-step and see if that works?

2. Reproduce the Issue in Isolation

So you think you know exactly what line of code is causing the issue, can you take just this line of code, or the concept for it, and create a pared down example using only that piece of code. See if the error still occurs in this pared down example – if so, great! Send it over to the Salesforce support team as a way of reviewing the issue. If not, great! You know it wasn’t that line of code causing the issue. Keep digging and see if you can determine what causes it to error.

3. Check for Missing Dependencies

Sometimes you can receive these errors through the standard UI, particularly in the setup menu. An example that I’ve seen before is when pressing the “View/Add Dependencies” button when working with change sets. The change set included some old reports that had been moved to an “Archived” folder but were still referencing fields and field values that no longer existed. The change set was not deploying so when the “View/Add Dependencies” button was pressed to help check everything required was included, the internal server error occurred.

In Summary

Hopefully you avoid getting any of these errors, but if you do stumble across an internal server error, or have found this page after receiving one, don’t panic. Follow some of the steps above, raise a case with Salesforce, and hopefully you’ll be back up and running in no time.