function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sharad Jain 9Sharad Jain 9 

Return count of files present in a folder of a directory

I want to write a method which return count of files present in a folder of a directory present externally or internally both
srlawr uksrlawr uk
Based on the info you have provided, I would recommend something like...
 
public static Integer numberOfFiles(String folderName) {

List<AggregateResult> ar = [SELECT COUNT(Id) totals FROM Document WHERE Folder.Name = :folderName];

return (Integer)ar.get(0).get('totals');

}

Not 100% sure on the casting there, might have to use Integer.valueOf();

and I typed that straight in here, so it might have other syntax errors in, if you just copy+paste it ;)​
mukesh guptamukesh gupta
Hi Sharad Jain,

Below SOQL will return your result
SELECT ContentType,FolderId FROM Document
 
SELECT count() FROM Document

Please MARK AS A BEST ANSWER!!!!

Thanks
Mukesh
srlawr uksrlawr uk
Sharad was after a method to return the numerical value, the SOQL snippets you have provided would

1) Return a list of every single document including ID of each folder and

2) Return an aggregate result that is the total number of every Document in the system, regardless of location