Salesforce Decode
Salesforcedecode
All topics

Learn SOQL & Data Modeling

Relationship queries, selectivity, aggregates, SOSL, and designing objects for scale.

120 questions in this topicDrill in practice mode →

Concept at a glance

Selective SOQL lets the query optimizer use indexes; good data modeling keeps queries simple at scale.

  • Selective filters & indexes
  • Relationship queries
  • Aggregates & GROUP BY
  • SOSL vs SOQL
SOQL & Data Modeling architecture diagram

Selective SOQL lets the query optimizer use indexes; good data modeling keeps queries simple at scale.

Difficulty Level

Topic Focus

Showing 40 of 120 SOQL & Data Modeling questions

Beginnersoqlrelationship-query

How do you write parent-to-child and child-to-parent relationship queries?

You need Accounts with their Contacts, and Contacts with their Account name, in one query each.

Beginnersoqlsearchsosl

What is the difference between SOQL and SOSL?

A global search box must find a term across Accounts, Contacts and Cases.

Beginnersoqldate-literals

How do date literals and date functions work in SOQL?

A report-style query needs Opportunities closing this quarter and Cases created in the last 7 days.

Beginnergovernor-limitssoql

What are the Salesforce governor limits for SOQL every developer should know?

Quick-fire limits round in an interview.

Beginnerbulkificationgovernor-limitssoql

Why should you never put SOQL inside a loop, and how do you fix it?

Code loops over trigger.new and queries the Account for each Contact.

Beginnersoqlexceptionsdebugging

What causes "List has no rows for assignment to SObject" and how do you avoid it?

Code like Account a = [SELECT Id FROM Account WHERE Name = :n]; fails in production.

Beginnersoqlaggregate

What is the difference between COUNT() and COUNT(Id)?

Quick SOQL syntax question.

Beginnersoqlschemarecord-types

How do you get the record type Id without a SOQL query?

Code queries RecordType in every trigger execution.

Beginnerdata-modellookupdelete-behaviour

What is the difference between a lookup "Clear the value" and "Don't allow deletion" option?

Deleting a Product should not leave Order Lines with blank product references.

Beginnersoqlorder-by

What does ORDER BY NULLS FIRST / NULLS LAST do?

A list sorted by Close Date shows blank dates at the top.

Beginnerbasicssoql

Explain SOQL to a SQL developer: what works differently?

Opening question in a developer interview.

Beginnerbasicssoqlorder-by

Write a query to get the 10 most recently created Accounts in India.

Live coding question.

Beginnersoqllikewildcards

How does the LIKE operator work in SOQL?

Find Contacts whose last name starts with "Pat".

Beginnersoqlin-operatorbind-variables

What is the IN operator and how is it used with bind variables?

You have a Set of Account Ids from a trigger and need their Contacts.

Beginnerapexsoqlcollections

What is the difference between a Set, List and Map when working with query results?

You need to look up Accounts by Id quickly inside a loop.

Beginnersoqlrelationship-queryowner

How do you query the Name of the record owner?

A report-like query needs Opportunity name and owner name.

Beginnersoqlaggregatehaving

What is the difference between WHERE and HAVING?

Find Accounts with more than 5 open Cases.

Beginnerdata-modelrecord-id

What is the difference between Id, 15-character Id and 18-character Id?

An Excel VLOOKUP on exported Ids matches the wrong rows.

Beginnergovernor-limitssoqldml

What is the maximum number of records a single DML statement can process?

Rapid-fire limits question.

Beginnerdata-modelself-relationship

What is a self-relationship and when do you use one?

Cases need a "Parent Case" to group related customer issues.

Beginnertroubleshootinggovernor-limitssoql

What does "Too many SOQL queries: 101" mean?

A user saving a single record gets this error.

Beginnerdata-modellookupownership

What is the difference between a lookup to User and the OwnerId field?

A custom "Account Manager" lookup to User is added, but it does not grant access.

Beginnerdata-modelobject-settings

What is the impact of the "Allow Reports" and "Allow Search" object settings?

A new custom object does not appear in reports or global search.

Beginnerdata-modelexternal-idunique

What is the difference between a unique field and an External ID?

An admin wonders whether to mark an Employee Number field as unique, external ID, or both.

Beginnerapexsoqlaggregate

What is an AggregateResult and how do you read it in Apex?

You need total pipeline per owner in Apex.

Beginnerapisoqlquery-all

What is the difference between "Query" and "QueryAll" in the API?

An integration misses deleted records when syncing.

Beginnersoqlpicklists

How do you query records by a picklist value that has been deactivated?

Old Cases still use a deactivated "Legacy" reason.

Beginnersoqlnulls

How do you write a query that returns Contacts without an Account?

Find private Contacts not linked to any Account.

Beginnersoqlrelationship-query

Write a query for Contacts with their Account's owner name.

Live coding.

Beginnersoqldate-literals

How do you find Opportunities closing in the next 30 days?

Live coding.

Beginnersoqlbind-variables

How do you query records created today by the current user?

Quick coding question.

Beginnerdata-modellookupformula-fields

What is the difference between a lookup field and a formula referencing a parent?

Show the Account Industry on Opportunity.

Beginnersoqlall-rows

What is the "ALL ROWS" keyword?

Quick question.

Beginnersoqlaggregate

How do you count records per Owner in SOQL?

Live coding.

Beginnersoqlpolymorphictypeof

What is SOQL's TYPEOF used for in one sentence?

Quick question.

Beginnerdata-modelpicklists

What is the difference between a Text field and a Picklist for categorisation?

Users type "Hi", "High", "HIGH" in a Priority text field.

Beginnerdata-modelrecord-types

What is the role of Record Types in data modeling?

Quick data modeling question.

Beginnerdata-modeljunction-object

How do you model many-to-many between Contacts and Events (conferences)?

Track which contacts attended which conferences.

Beginnersoqlaggregateroll-up

What is the difference between COUNT() in SOQL and a roll-up summary?

Count child records for display.

Beginnersoqlrelationship-query

How do you query records based on a field in a grandparent object?

Find Cases whose Account's parent is in Germany.