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
Natraj Subramani 15Natraj Subramani 15 

Lines of Code - Lightning Components

Hi All,

I am able to retrieve the lines of code for Classes/Pages and Triggers using the below code. Is there a way to extract lines of code for lighting components ? Any help is appreciated.

Integer classLines = 0;

Integer triggerLines = 0;

Integer pageLines = 0;

for(ApexClass a : [Select Body From ApexClass]){

                    List<String> lines = a.Body.split('\n');

                    classLines += lines.size();

}

for(ApexTrigger a : [Select Body From ApexTrigger]){

                    List<String> lines = a.Body.split('\n');

                    triggerLines += lines.size();

}

for(ApexPage a : [Select Markup From ApexPage]){

                    List<String> lines = a.Markup.split('\n');

                    pageLines += lines.size();

}


system.debug('Apex Class lines: ' + classLines);

system.debug('Apex Trigger lines: ' + triggerLines);

system.debug('VisualForce lines: ' + pageLines);

system.debug('Apex Total lines: ' + (classLines+ triggerLines+pageLines));

Thanks
Natraj
Raj VakatiRaj Vakati
I dnt think so .. 

As per the SOAP APi document   AuraDefinitionBundle is not supported number of lines  and Markup field s
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_auradefinitionbundle.htm?search_text=Aura
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_auradefinition.htm?search_text=Aura
Amit Chaudhary 8Amit Chaudhary 8
Natraj Subramani 15Natraj Subramani 15
Hi Raj and Amit,

Thank you for the response. AuraDefinitionBundle does not have a Markup field.

I tried AuraDefinition Source field and it does return some lines of code. I am still not sure if its looking into the correct one.

Integer componentLines = 0;
for(AuraDefinition a : [Select Source  From AuraDefinition]){

                    List<String> lines = a.Source .split('\n');

                    componentLines += lines.size();

}

system.debug('Component lines: ' + componentLines);

Thanks
Natraj
Natraj Subramani 15Natraj Subramani 15
Update

The above code worked and its accurate for lighting components. You can create similar ones for Apex Class (Refer Body), ApexTrigger (Refer Body) and ApexPage (Refer Markup) as well.

Thanks
Natraj