What is SOQL and how do you write relationship queries?
Suggested answer
SOQL (Salesforce Object Query Language) queries data from the Salesforce database. Child-to-Parent (traverse up): SELECT Name, Account.Name FROM Contact — reference parent fields using the relationship name. Parent-to-Child (subquery): SELECT Name, (SELECT LastName FROM Contacts) FROM Account — use the child relationship name in parentheses. Aggregate functions: COUNT(), SUM(), AVG(), MIN(), MAX() — used with GROUP BY. SOQL injection prevention: Never concatenate user input directly into SOQL strings. Use bind variables (WHERE Name = :userInput) or String.escapeSingleQuotes() for dynamic SOQL to prevent injection attacks.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.