Learn to use the exponentiation operator

Photo by recha oktaviani on Unsplash

Arithmetic with exponents used to be an unsuspecting hassle. Legacy languages or even older versions of more current languages required standalone functions or even imported methods to raise a number to a given power.

For example, in C++ we’ll need to include the library and use the function. Similarly, older version of PHP use the function, albeit without import. If you’ve worked with JavaScript you may have seen the method.

Granted many older languages have since implemented improvements for exponentiation, Python has been silky smooth since the beginning.

Exponentiation Operator in Python

Raising a number to an exponent in Python…


Avoid the biggest mistake you’ll need to unlearn

Photo by Axel Ahoi on Unsplash

Unless learning and using Salesforce is your sole full-time job then you’re most likely in “do now, learn later” mode. Whether you’re a sales, marketing, or customer success team lead or an army of one trying to keep your business organized, you’re short on time and care about the results more than the process.

If there was one thing I could hit the pause button on, making you stop and learn first it’d be bulkification. This is for three reasons: (1) it’s easy to learn, (2) it’s easy to implement, (3) it’s a nightmare to unlearn and undo if overlooked.


Two simple solutions for this common need

Photo by Waldemar Brandt on Unsplash

The Date Class in Apex has some really nifty methods such as and — methods you didn’t know you needed, but you’re glad when you eventually do. Unfortunately, the quality of life methods exclude one that returns the name of the month. The most we have at our disposal is the numeric month value, but that’s not always sufficient.

In this article, we’ll discuss two strategies to lookup the name of a month from a Date Class instance. Each technique has their own pros and cons, so it’s up to you to pick the one you prefer.

The DateTime Class

If you’ve…


Tutorial using Apex Triggers and Classes

Photo by Daria Shevtsova on Unsplash

The number of contacts per account is one of the first things anybody new to setting up Salesforce is interested in tracking. Unfortunately, a simple roll-up summary is not possible because the Contact sObject is a standard object.

Being unable to solve this requirement with a simple field, we need to use some of the Developer tools in Salesforce to auto-magically maintain this relationship between Account and Contacts.

In this tutorial we’ll use an Apex Trigger as the primary mechanism for tracking the number of contacts. …


Query individual terms across multiple objects and fields

Photo by Tobias Fischer on Unsplash

Salesforce is fantastic for structuring data…a lot of data. You’ve taken the time to create a library of sObjects, broken apart all the data, but what happens when you want to do a search across multiple sObjects?

This is where Salesforce Object Search Language (SOSL) comes into play.

SOSL is perfect for querying names, emails, and other text-based data across a specified list of sObjects. Do you want to look into all the leads and opportunities that involve a specific email address? SOSL is your best friend.

We’re going to define the different parts of a SOSL query and go…


Easily query an object’s parent or child data

Photo by ketan rajput on Unsplash

SOQL — Salesforce Object Query Language — is a mechanism for retrieving object data that resembles SQL. While SQL includes operations such as INSERT, ALTER, and DELETE, SOQL is confined to retrieving data…effectively SELECT statements only.

While this may seem confining, the reality is that SOQL has many quality-of-life improvements for working with Salesforce objects (sObjects). One of these perks is the way in which related parent and child data can be automatically retrieved without using JOIN statements.

In this article, we’ll go over two examples: how to include parent object data in a SOQL query and how to include…


An introduction to complex data types

Photo by Emma Matthews Digital Content Production on Unsplash

Apex — the Salesforce programming language that is similar to and based on Java — includes both primitive and complex data types. A data type defines the type of value(s) that can be stored in a given structure since Apex is a strongly-typed language.

Primitive types — such as String, Integer, and Decimal — hold a single value. Conversely, Collections are Apex data types that may hold multiple values in a single identifier.

In this article, we’ll introduce the three types of Collections, when to use each, and provide example code to get you started.

Lists

Lists are an ordered collection…


Learn to divide and ignore the remainder

Photo by Dan Meyers on Unsplash

What is Integer Division?

Integer division is an arithmetic operation where division is performed, but the remainder is discarded leaving us with just an integer.

In other programming languages, the combination of division plus something akin to a “floor” function is used to achieve similar results.

Here’s an example in JavaScript:

Having to round-down a normal division operation may not be particularly difficult, but it can be annoying and inconvenient. Fortunately, Python has us covered with the integer division operator.

Integer Division in Python

Many popular languages such as JavaScript, Java, and PHP use the double…


Get rid of cumbersome elif trees with pattern matching

Photo by elen aivali on Unsplash

Whenever I’m asked “why Python?” the answer undoubtedly revolves around its ease-of-use and human-logical style of syntax. Especially coming from other languages such as PHP, Java, or JavaScript, Python simply makes more sense.

Starting in version 3.10, one of my last grievances with Python — relative to other languages — is being addressed: the beloved switch statement.

In this article, we’ll introduce what switch statements are and how they are implemented in Python. Enjoy the tutorial and look forward to some refactoring!

What is a Switch Statement?

For the uninitiated, a switch statement is a programming decision structure where one of multiple branches is executed…


A simple JavaScript function to find all unique values

Photo by Jakob Owens on Unsplash

In a previous article — Three Easy Ways to Remove Duplicate Array Values in JavaScript—we covered three different algorithms to create an array of unique values. The most common request that came from that article was a similar mechanism for a key in an array of objects.

In this article we’ll cover two separate algorithms to accomplish this and wrap up the guide with a recommendation for generalizing the strategy for easy repeated use.

Starting Data

Before we begin, here’s the data set we’ll be using. …

Jonathan Hsu

Top writer with 2M+ views. Follow me at medium.com/code-85 and medium.com/growth-85

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store