Get your Salesforce project stats using Apex

I mentioned recently that I was working an a rather large project and posted some stats on how many classes, custom objects, etc were involved. Of course, I didn’t count those by hand. I wrote a little script that I run via Execute Anonymous either in Eclipse or in the System Log. Thought I’d share that out.

In the code below I filter out any managed packages because I just wanted stats on stuff that I had done. Feel free to modify the queries to your specific needs.

 


Integer triggerCount = 0;
Integer codeLines = 0;
Integer classCount = 0;
Integer componentCount = 0;
Integer pageCount = 0;
Integer customObjectCount = 0;
for (ApexTrigger t : [Select a.NamespacePrefix, a.Name, a.LengthWithoutComments From ApexTrigger a where NamespacePrefix = null]){
triggerCount++;
codeLines += t.LengthWithoutComments;
}
for (ApexClass a : [Select a.NamespacePrefix, a.Name, a.LengthWithoutComments From ApexClass a where NamespacePrefix = null]){
classCount++;
codeLines += a.LengthWithoutComments;
}
for (ApexComponent c : [Select a.NamespacePrefix, a.Id From ApexComponent a
From ApexComponent a where NamespacePrefix = null]){
componentCount++;
}
for (ApexPage p : [Select a.NamespacePrefix, a.Id From ApexPage a
From ApexPage a where NamespacePrefix = null]){
pageCount++;
}
Map gd = Schema.getGlobalDescribe();
for (Schema.SObjectType s : gd.values()){
Schema.DescribeSObjectResult r =s.getDescribe();
if (r.isCustom()){
customObjectCount++;
}
}
system.debug('---------Project Stats---------')
system.debug( 'triggerCount = ' + triggerCount);
system.debug( 'codeLines = ' + codeLines);
system.debug( 'classCount = ' + classCount);
system.debug( 'componentCount = ' + componentCount);
system.debug( 'pageCount = ' + pageCount);
system.debug( 'customObjectCount = ' + customObjectCount);

Advertisements
This entry was posted in Salesforce, Web/Tech. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s