Basics

SOQL Data Types

SOQL Data Types

SOQL data types include String Number and Date with type safety.

Introduction to SOQL Data Types

In Salesforce Object Query Language (SOQL), data types play a crucial role in defining the format and nature of the data you work with. Understanding these data types helps in crafting precise queries and ensures data integrity and type safety. This guide will walk you through the basic data types available in SOQL, including String, Number, and Date.

String Data Type

The String data type in SOQL is used to represent textual data. It can include letters, numbers, and special characters, and is enclosed in single quotes. Strings are case-sensitive in SOQL.

Here's an example of using a string in a SOQL query:

Number Data Type

The Number data type in SOQL is used for numerical values, which can include integers and decimals. It is essential for operations that involve arithmetic calculations or comparisons.

Example usage of a number in a query:

Date Data Type

The Date data type in SOQL is used for date and time values. Salesforce provides a wide range of date functions to manipulate and filter date fields within your queries.

Below is an example of using dates in a SOQL query:

Type Safety in SOQL

SOQL ensures type safety by enforcing that the data types used in queries are compatible with the fields they are interacting with. This prevents errors that may arise from type mismatches, such as trying to compare a string to a number.

For example, when filtering records based on a number field, ensure that the comparison value is also a number:

In this query, NumberOfEmployees is a number field, and the comparison value 50 is correctly specified as a number.

Previous
Fields