SOQL (Salesforce.com Object Query Language)As a developer, you are no doubt already familiar with some query languages. The most common query language is SQL, or Standard Query Language, the universal standard for interacting with relational databases.
Just as the Force Platform data repository is similar to a relational database, SOQL is similar to SQL. In most places where there is overlapping functionality, the syntax for SOQL is identical to SQL. But there are a few important differences between the two data access languages.
- SOQL is a query-only language – SQL has syntax for both reading and writing data, while SOQL is only used to retrieve records from your Force Platform objects. Later in this chapter, you will learn about how to write data using Apex data manipulation language.
- SOQL uses relationships, not joins – In SQL, you implement relationships between tables using join syntax in the where clause of the query. SOQL syntax recognises relationship fields to identify the connections between objects, but does not support join syntax. You will see how to use relationships in your SOQL statements in the next section.
- SOQL does not support all SQL keywords – SOQL syntax is described in brief in the following section, and in more detail in the Force Platform API documentation. You should assume that SQL syntax not covered in the documentation is not accepted in SOQL.
Why not SQL?As a developer, your career might have encompassed using several different relational databases, and all of them used a similar form of SQL. You might be asking yourself the question in the title of this sidebar—why didn't the Force Platform developers use SQL?
The simple answer is that Force Platform objects are not the same as SQL tables and the Force Platform data store is not the same as a relational database. Access to data is always through some dialect, rather than directly, whether that interface is SQL or something else. In this fashion, SOQL provides query capabilities for Force Platform objects. The Force Platform environment offers you a lot of functionality and developer productivity based on the use of these objects, which are not the same as relational tables.
The complete Force Platform platform gives you everything you need to store and manipulate your data–the language and methods used to accomplish these ends are just a little different than those used for classic relational databases.