MALFORMED_QUERY: Cross join is not supported in SOQL
What does this error mean?
SOQL does not support JOIN syntax. Relationships between objects are queried through Salesforce's relationship model — either via child relationship subqueries in the SELECT clause (for one-to-many) or parent field traversal (for many-to-one/lookup). Attempting to use SQL's JOIN, CROSS JOIN, or comma-separated object lists produces this error.
SOQL is intentionally designed around Salesforce's relationship model rather than the relational algebra of SQL. Queries are always anchored to a primary object, with related data accessed through defined relationships.
Common Causes
1. Using SQL JOIN syntax directly
Writing FROM Account a JOIN Contact c ON c.AccountId = a.Id — this is valid SQL but completely unsupported in SOQL.
2. Comma-separated object list
Writing FROM Account, Contact attempting an implicit cross join — another SQL pattern that SOQL doesn't support.
How to Fix It
Solution 1: Use relationship subqueries for child data
-- ❌ SQL JOIN — not supported in SOQL
SELECT a.Name, c.Email
FROM Account a JOIN Contact c ON c.AccountId = a.Id
-- ✅ SOQL relationship subquery (parent → children)
SELECT Id, Name,
(SELECT Id, Email FROM Contacts)
FROM Account
WHERE Id IN :accountIds
Solution 2: Use parent field traversal for lookup data
-- ✅ SOQL parent traversal (child → parent fields)
SELECT Id, Name, Account.Name, Account.Phone
FROM Contact
WHERE Account.Industry = 'Technology'
Solution 3: For unrelated objects, use two queries in Apex
// Two separate queries, merged in Apex
Map<Id, Account> accountMap = new Map<Id, Account>(
[SELECT Id, Name FROM Account WHERE Id IN :accountIds]
);
List<Contact> contacts = [
SELECT Id, Name, AccountId
FROM Contact
WHERE AccountId IN :accountIds
];
for (Contact c : contacts) {{
Account acc = accountMap.get(c.AccountId);
// combine data in Apex
}}