Salesforce introduced in Spring 20 an object called VisualforceAccessMetrics which summarizes the usage of VF pages, see more here
The object holds VF access summary data for 1 year, you can check this by finding the oldest record in the object with
SELECT MIN(LogDate) FROM VisualforceAccessMetrics
substitute MIN for MAX to find latest record
Old production orgs can have a lot of old VF pages (+controllers and corresponding tests) which are not used anymore when customer has transitioned to using LWC
The VisualforceAccessMetrics object can be used to find VF pages that have not been accessed for a year and thus are potential candidates for deletion.
Example code to find candidates
Set<Id> vfPageUsed = new Set<Id>();
List<AggregateResult> vfUsages = [SELECT ApexPageId, COUNT(Id) FROM VisualforceAccessMetrics GROUP BY ApexPageId];
for(AggregateResult vfUsage : vfUsages){
vfPageUsed.add(((Id)vfUsage.get('ApexPageId')));
}
List<ApexPage> apexPagesNotAccessed = [SELECT Id, Name, LastModifiedDate, LastModifiedBy.Name FROM ApexPage WHERE Id NOT IN :vfPageUsed AND NamespacePrefix = null ORDER BY LastModifiedDate DESC];
for(ApexPage apexPage:apexPagesNotAccessed){
System.debug('Id: '+apexPage.Id + ', Name: ' +apexPage.Name+ ', Last modified:'+apexPage.LastModifiedDate+', Last modified by: '+apexPage.LastModifiedBy.Name);
}
Code lists the VF pages without a namespace (NamespacePrefix = null). Remove this criteria to list VF pages also from managed packages.
Go through each VF page and check if it is used (for example by asking customer), if it is not used
- Check Apex controller, if it is not used in any other VF page (or anywhere else), it can be deleted. It is easy to find references with
Find Usagescommand in Illuminated Cloud. Another way to find references is to use plain metadata search. - Controller is many times referenced in apex test also. This means that the test can be deleted also provided that it is not used to test apex code that is used. Deleting tests is especially useful because it will speed up deployments to production (especially if running all tests)
Note! It seems Salesforce Scale Center does not list unused VF pages (or VF page controllers)

Leave a comment