Last active
November 26, 2024 05:44
-
-
Save stomita/1e08c7387a7ed3ca8e90e6d0b6d6a58c to your computer and use it in GitHub Desktop.
SOQL OFFSET with long text area fields in the query cause unexpected record cut-off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* setup */ | |
Account[] accs = new Account[] {}; | |
for (Integer i = 1; i <= 3000; i++) { | |
accs.add(new Account(Name = 'Test Account #' + i)); | |
} | |
insert accs; | |
/* start test */ | |
Account[] recs; | |
recs = [ | |
SELECT Id, Name, LongTextarea01__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
]; | |
// expected to show `3000`, and actually does. | |
System.debug('Rows = ' + recs.size()); | |
recs = [ | |
SELECT Id, Name, LongTextarea01__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]; | |
// expected to show `2999`, and actually shows `250` | |
System.debug('Rows (with offset 1) = ' + recs.size()); | |
recs = [ | |
SELECT Id, Name, LongTextarea01__c, LongTextarea02__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]; | |
// expected to show `2999`, and actually shows `125` | |
System.debug('Rows (with offset 1, two LTA fields) = ' + recs.size()); | |
recs = [ | |
SELECT Id, Name, LongTextarea01__c, LongTextarea02__c, LongTextarea03__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]; | |
// expected to show `2999`, and actually shows `62` | |
System.debug('Rows (with offset 1, three LTA fields) = ' + recs.size()); | |
recs = [ | |
SELECT Id, Name | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]; | |
// expected to show `2999`, and actually does. | |
System.debug('Rows (with offset 1, no LTA fields) = ' + recs.size()); | |
Integer cnt; | |
cnt = 0; | |
for (Account rec: [ | |
SELECT Id, Name, LongTextarea01__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]) { | |
cnt++; | |
} | |
// expected to show `2999`, and actually shows `200`. | |
System.debug('Rows (with offset 1, using for-loop) = ' + cnt); | |
cnt = 0; | |
for (Account rec: [ | |
SELECT Id, Name, LongTextarea01__c, LongTextarea02__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]) { | |
cnt++; | |
} | |
// expected to show `2999`, and actually shows `200`. | |
System.debug('Rows (with offset 1, two LTAs, using for-loop) = ' + cnt); | |
cnt = 0; | |
for (Account rec: [ | |
SELECT Id, Name, LongTextarea01__c, LongTextarea02__c, LongTextarea03__c | |
FROM Account | |
WHERE Name LIKE 'Test Account%' | |
OFFSET 1 | |
]) { | |
cnt++; | |
} | |
// expected to show `2999`, and actually shows `200`. | |
System.debug('Rows (with offset 1, three LTAs, using for-loop) = ' + cnt); | |
/* teardown */ | |
delete accs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment