Converting 15-Character Salesforce IDs to 18 Characters

I spent the past few days baselining the data in a system that one of our Salesforce Orgs will be integrating with. Unfortunately I have to convert our Salesforce record IDs into the 18-character form because this system’s database isn’t set up to handle the case-sensitive 15-character IDs. This is something I used to do frequently as a consultant and I had various scripts in my toolbelt but I went a-searching to see what the ecosystem had created since then. And there are quite a few options! From scripts in various languages to online tools but I found all of them missing key features I needed i.e. To address these gaps I created an NPM package as well as an online ID converter. So you can also benefit from these additional (admittedly small but important to me) benefits.

Google Maps Cannot Be Used In Lightning Web Components

Recently I was tasked with investigating which 3rd-party mapping solutions can be used within Salesforce lightning web components. And boy-oh-boy is there a lot of misinformation out there. Especially on the topic of using Google Maps within LWCs. I’ll start by saying this: you cannot use Google Maps in LWCs (Visualforce is still an option though). The odd thing is that several, high-ranking (in Google Search) blogs say you can. Some even have code samples! I have a theory on why this is the case. If you ask the most used AI tools out there many will declare that you can indeed use Google Maps within LWCs. And I suspect that bloggers who didn’t know better ran with this answer and started generating content and code from those AI tools. Once again, you cannot do this. There is no secret tag you can include in the markup. No, you cannot …

Read more

Salesforce: Yet Another JSON to Apex Converter

A screenshot of the JSON to Apex Converter tool

I’ve been doing a lot of Salesforce integration as part of my most recent role. And where there’s integration, there’s JSON. The vast bulk of this work is integration using Apex, and so I began brushing up on what’s changed since I last got in the weeds many years ago. How much has changed? Surprisingly, not much! Depending on your situation, there are broadly 3 options when it comes to handling JSON in Apex: The options are in order of difficulty. Additionally, options 1 and 3 make for code that is much easier to work with because the Apex Types you define are strongly typed. But option 1 isn’t always possible e.g. if the JSON you’re working with uses reserved keywords, or if you want to process part of the JSON before sticking it in an Apex structure. However, this blog post is not about the various approaches and their …

Read more

Salesforce: Sending emails from communities doesn’t work

I’ve been doing a lot of work with Communities AKA Experience Sites recently and encountered an issue where emails sent using the Apex method Messaging.sendEmail() were not be received by the recipient. The strange thing was that the debug logs showed that the email had been successfully sent, and the associated Activity record had been created. And thus began many hours of debugging to understand the root cause and its fix. I tried the usual suspects: None of the above worked. When I checked the Email Logs there was still no entry for the email despite the Apex code saying it had successfully gone out. Then I came across an article in the Winter ’24 release notes saying the email addresses must be verified to send emails through Salesforce. Aha! Or so I thought. For standard Salesforce users, you’ll see “[Verified]” next to their email address. Or, if they’re not …

Read more

Salesforce LWC: “Error: Failed to execute ‘removeChild’ on ‘Node’: The node to be removed is not a child of this node. at HTMLDivElement.removeChild”

I recently came across this error when implementing the 3rd party image carousel library called Glider into a Salesforce lightning web component. The message doesn’t give much away, does it? Given the hours I lost investigating the issue I thought I’d share the solution. Salesforce does not like 3rd party libraries manipulating the DOM. They do make it possible though e.g. if you know that the library is going to inject elements into a container element you can flag that container element like so: However, some libraries require that you partially set up an expected DOM structure and then the library’s initialisation sprinkles whatever else it needs within that structure. In my case, Glider injects a “track” (wrapper) <div> around the elements that you can flip through. Interestingly, SF LWC is fine with this unless you are conditionally re-rendering the part of the page that contains Glider. In that case, …

Read more

Using Native Mobile Device Features from Visualforce with Phonegap

The prospect of learning hybrid mobile development is daunting for most Salesforce developers. There are just so many new things to learn all at once. And so, whilst recently learning Phonegap, Ionic, Angular and responsive-design for a side project I realised that there is a very simple bridging approach that can teach you some of the basics and that might even result in some cool apps. This bridging is achieved by making the native features of a mobile device (GPS, local storage, camera etc.) directly accessible from Visualforce. It is dead easy. I swear. And will demystify the hybrid development paradigm for you. Set up Phonegap Install Phonegap and Set up an empty project For this post I’m assuming you know that Phonegap is a framework that allows you to build web applications that are then bundled into native containers (and iOS container for Apple devices, and Android Container for …

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 3. Polymorphism

This is part 3 in the series “A Beginner’s Guide to Object-Oriented Programming with Apex” and will cover the aspect of Polymorphism. For other posts in this series see the links below. A Beginner’s Guide to Object-Oriented Programming with Apex What the hell is Polymorphism? Polymorphism has the funkiest name and is my favourite aspect of OOP. If done correctly you will feel like a proper genius. Originating from Greek words, polymorphism more or less means “many forms”. This gives away very little unless you know polymorphism quite well but essentially polymorphism describes the ability of a type e.g. a set of differing Apex classes, to be used in similar ways without knowing much about those classes. An immediate example on the platform is the Type.format() static method available on Integers, DateTime, etc**. Although each of the Types represents something different this method does a similar thing for each i.e. turns …

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 2. Abstraction

This is part 3 in the series “A Beginner’s Guide to Object-Oriented Programming with Apex” and will cover the aspect of Abstraction. For other posts in this series see the links below. A Beginner’s Guide to Object-Oriented Programming with Apex What the hell is Abstraction? Abstraction is a very interesting and surprisingly simple concept. At its core it’s about context and if Abstraction were a company it’s motto would be “Provide the right tools and data at the right time.”. There are many analogies in the “real world” e.g. Where is this applicable to developers on the platform? Ever created a Visualforce component or Apex utility class? Well you my friend you are already using abstraction! This sounds a lot like Encapsulation! Abstraction and Encapsulation go hand in hand but they are different. Encapsulation is one of the ways you can achieve abstraction but does not encompass the entire concept. …

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 1. Encapsulation

This is part 2 in the series “A Beginner’s Guide to Object-Oriented Programming with Apex” and will cover the aspect of Encapsulation.

A Beginner’s Guide to Object-Oriented Programming with Apex

  1. Introduction
  2. Encapsulation (this post)
  3. Abstraction
  4. Polymorphism

What the hell is Encapsulation?

Encapsulation isn’t a tricky concept in itself but some confusion does arise from it’s close relationship with Abstraction (to be covered in my next post). Broadly it is defined as one of, or both of the following:

  1. An information hiding mechanism.
  2. A bundling of data and methods that operate on that data.

These are pretty abstract statements but in reality are very simple. I will demystify them with examples below but for now let’s use an analogy:

Imagine you have a watch (or if you have one just consider it, don’t worry about the imagining part) that tells you the date and time. You can adjust the date and time using buttons/knobs/switches but you have no idea what happens inside the watch, just that it results in the date and time changing. You have some data (the date and time), you have some methods to operate on that data (buttons/knobs/switches) and there is a whole lot of stuff going on in the background that you don’t know about (and it’s better that way, imagine you had to adjust all those bits and pieces yourself).

That’s encapsulation baby!

Read more

A Beginner’s Guide to Object-Oriented Programming with Apex: 0. An Introduction

Apex has come a long way in the past few years, and as Salesforce has grown so has the number of super smart people working on the platform. There are lots of guides on how to do fancy things using JavaScript, Apex and Visualforce as well as many more whitepapers on the topics of governances and standards. However I think there is a gap, and I’d like to plug it. Over the next few weeks and months I will be releasing articles that describe and show the basics of object-oriented programming (OOP) with Apex. My approach will be to make these articles as modular and simple as possible. The target audience? Developers with a-teeny-bit-of-experience through to those who have tons of experience but never had any formal training in OOP. A Beginner’s Guide to Object-Oriented Programming with Apex What the hell is OOP? Good question, and although many agree on …

Read more