I would like to get the record count from each object (there are fair chances of getting more than 50K records) using a desktop utility and would like to create one CSV file for each object's record count till date.
1 Answer
You can use the @ReadOnly annotation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_ReadOnly.htm
Find below the test that I have done:
This code is without @ReadOnly annotation:
@RestResource(urlMapping='/AccountCount/*')
global class AccountCount_WS {
@HttpGet
static webservice Integer getCountAccount(){
Integer count = [select count() from Account];
//just to reach more than 50k because in my sandbox I have arround 17k
count += [select count() from Account];
count += [select count() from Account];
count += [select count() from Account];
return count;
}
}
and here I get an error when I call the WS:
[{
"errorCode": "APEX_ERROR",
"message": "System.LimitException: Too many query rows: 50001\n\nClass.AccountCount_WS.getCountAccount: line 9, column 1"
}]
Then I added an @ReadOnly annotation like below
@RestResource(urlMapping='/AccountCount/*')
global class AccountCount_WS {
@HttpGet
@ReadOnly
static webservice Integer getCountAccount(){
Integer count = [select count() from Account];
//just to reach more than 50k because in my sandbox I have arround 17k
count += [select count() from Account];
count += [select count() from Account];
count += [select count() from Account];
return count;
}
}
The WebService is now able to return a value:
68992
hope it clarifies
-
Hi @Akram, thank you for the response. I wouldn't want writing custom Apex API for this instead looking for online documentation for maximum rows supported by standard REST or SOAP APIs. Unfortunately didn't find in the API documentation but I think I have got what I was looking for in this post. - salesforce.stackexchange.com/questions/118949/…– LakhanPDec 21, 2016 at 11:41