You need to sign in to do that
Don't have an account?
moverdorf
How To Get The Record Count Of SOQL query into a variable...
Hi, I want to return the record count of a dynamic SOQL query, (checkVal is passed in so don't worry about that):
Public List<sObject> lstObj;
Public Integer totRecsToProcess;
mystr = '[select count() from payout__ImportStaging__c where payout__BD_Id__c = \'' + String.escapeSingleQuotes(checkVal) ;
lstObj = Database.query(mystr);
I want to set totRecsToProcess equal to the count() value returned, can someone please tell me the correct syntax for that?
Thanks.
You can use the database.countQuery method to get the count of the dynamic SOQL
All Answers
The result of the call is going to be an integer. I do something similar...
Integer AlreadyThere = [SELECT count()
FROM AccountContactRole__c
WHERE Account__c = :vACRobject.Account__c
And Contact__c = :vACRobject.Contact__c LIMIT 1];
Does that help?
Your solution only works if it isn't dynamic SOQL.
I need to first create the Sobject based on the value of the Mystr, and then reference the count from the Sobject, which I am unsure how to so syntactically.
You can use the database.countQuery method to get the count of the dynamic SOQL
Thank you!