Introduction
Salesforce has introduced significant changes to SOQL in its latest release. These updates impact how you construct and execute queries. While these modifications aim to enhance query performance and accuracy, they may necessitate adjustments to your existing code.
Changes in SOQL Error Codes and Functionality
Changed Error Codes:
- The error code MALFORMED_QUERY now replaces D_QUERY_FILTER_OPERATOR.
Changed Functionality:
- Negative currency values are now permissible in queries.
- For example: Balance__c < USD-500
Changed Error Messages:
Below are examples illustrating how error messages have evolved:
Invalid SOQL Queries:
- Query:
SELECT Id
FROM Account USING everything
-
- Old: unexpected token: ‘<EOF>’
- New: unexpected token: ‘everything’
Quotes Surrounding an Unexpected Token:
- Query:
SELECT annualrevenue, parentid FROM Account
WHERE (isDeleted = false AND NumberOfEmployees != 100)
OR (isDeleted = false AND Site = ‘999’)
AND ParentId = ‘000000000000000’ LIMIT 50000 OFFSET 0
-
- Old: unexpected token: AND
- New: unexpected token: ‘AND’
SELECT Id,FirstName, LastName,Name, Email, Phone, MobilePhone, Company, Street, City, State, PostalCode, Country, Region__c,OwnerId, owner.name
FROM Lead
WHERE RecordType.name=’Commercial’AND Company LIKE ‘%GM%’ OR Domain__c=’gm.com’
- Old: unexpected token: OR
- New: unexpected token: ‘OR’
Using NULL Literals in WHERE Statements:
- Query:
SELECT Id, Name, Country__c, State__c, City__c, PAN_Number__c
FROM Account
WHERE PAN_Number__c like NULL AND Name LIKE ‘%a%’
-
- Old: invalid operator
- New: unexpected token: ‘OR’
More Than Two Nested Functions:
- Query:
SELECT convertCurrency(calendar_year(convertTimezone(lastmodifieddate)))
FROM account
-
- Old: expecting a right parentheses, found ‘(’
- New: unexpected token: ‘(’
Invalid Datetime Literals:
- Query:
SELECT Id
FROM Account
WHERE SystemModstamp > 2023-12-12t12:12:00-25:00
-
- Old: line 1:67 mismatched character ‘5’ expecting set ‘0’..’3′
- New: Invalid datetime: 2023-12-12t12:12:00-25:00
Using “WITH SECURITY_ENFORCED” Without a Proper Apex Context Setup:
- Query:
SELECT Id
FROM Account WITH SECURITY_ENFORCED
-
- Old: SECURITY_ENFORCED not allowed in this context
- New: rule soqlWithIdentifierClause failed predicate: {this.helper.allowApexSyntax() && this.helper.hasApexContext()}
Additional Considerations:
- Running SOQL queries against DMOs can consume Data Services credits from your Data Cloud subscription. Exercise caution when using features such as ‘FOR’ loops, query locators, recursion, or any method that results in multiple queries to Data Cloud.
- For detailed information on usage billing, please refer to the Data Cloud Billable Usage Types documentation.
Conclusion
- To ensure your SOQL queries continue to function correctly, it’s crucial to familiarize yourself with the new syntax and error handling rules. Thoroughly review your code for potential impacts and make necessary modifications. By staying updated on these changes, you can leverage the full capabilities of SOQL in your Salesforce applications.
Recent Post:
1.Integrating Lightning Web Components (LWC) with Visualforce Pages in Salesforce
2.Enhancing Salesforce List Views with Lightning Web Components and Apex