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

Salesforce: Universal Batch Scheduling Class

I’d like to propose a new way of working with scheduled batch classes. I’ve worked on several hundred Salesforce projects in the past few years and often see batch scheduling classes being created per scheduling requirement and it grinds my OCD – not in a good way. In most cases you should only need one “Batch Scheduler” per Org, let me demonstrate how and why. The Universal Batch Scheduler™ Requirements Let’s assuming you have a batch class that you need to run on a repeated schedule*, such a class signature is given below. That class will have to obey some conventions such as implementing the Batchable interface as shown in the standard documentation. [code language=”Java”] global class MyBatch implements Database.Batchable<SObject> { // … } [/code] * For one off, schedule execution of batch classes you can use the System.ScheduleBatch() method. The Scheduler Now you might be tempted to created a scheduled …

Read more

If This Then Salesforce

I’ve been enjoying IFTTT for a while now and if you haven’t experimented with it yet then I’m not sure we’ll ever be friends. Essentially it’s a very easy tool that lets you set triggers on a source API e.g. Foursquare and have some information from that API be posted to a target API e.g. Jawbone Up. IFTTT calls these recipes and I’d like to demonstrate some particularly delicious combinations that can be used with Chatter. Salesforce Org Alerts and Known Issue posted to Chatter Salesforce makes Instance Alerts e.g. “Perfomance degradation on EU0.” available through an RSS feed so all you need to do is create a recipe (or copy mine) that monitors the appropriate RSS url for changes and posts to a particular Chatter group. You can do a similar thing with Salesforce Known Issues. Tweets posted to Chatter Quite often there are interesting tweets that I want to …

Read more

Salesforce Analytics API Sample Code

A picture is worth a thousand words, so goes the justification for graphic novels. I kid, I love the hell out of graphic novels but now I’ve been sidetracked and this is only the second sentence of this post. So, the Analytics API. I’m pretty enamoured with it as it seems is Pat Patterson, and I think that it’s one of the most useful features the platform has ever made available. Presenting the right chart (or set of charts) to a manager or executive can empower them to make business decision in minutes, powerful stuff. To that end myself and a few of my fellow Tquilites have begun building an opensource library of Analytics API demos to aid you in aiding your clients/managers/execs. Below I’ve included a few introductory steps to help you get started. To start with you’ll need the code from github. Step 0 I’ll be stepping through …

Read more

Developing Chrome Extensions for Salesforce

Chrome extensions are awesome, they provide amazing convenience that is limited only by your imagination. There are some amazing Chrome Extensions for Salesforce already, some of my favourites being: As a great fan of JavaScript I’ve always wanted to create a Chrome Extension for Salesforce and I’ve finally gotten around to it. The hardest part was figuring out what context the JS executes in (e.g. in the current tabs context, or in some separate context). Let me step through the code to show you how it’s done. Chrome Extension Structure A Chrome Extension is made up of a JavaScript, HTML, images and JSON. At its core is a manifest file which contains the metadata describing your application in JSON. There is a lot of documentation about the structure of this file but some of the key elements are shown below. This file references all external resources (JavaScript, images etc.), the …

Read more