-1

I am trying to get a list of reports that need to be deleted from Salesforce. I have created a report of reports with the below criteria.

enter image description here

The report seems fairly accurate and I am trying to get the same list of reports via SOQL and I have constructed the SOQL as below.

SELECT Id, Name, DeveloperName, FolderName, LastRunDate from Report WHERE LastRunDate != LAST_N_MONTHS:6 AND (NOT FolderName LIKE '%Marketing%') AND (NOT FolderName LIKE '%Sys Admin%') AND (NOT FolderName LIKE '%Marketing%') 

Unfortunately, the SOQL results doesn't seem to be accurate. When I compared the Report Id from the report spread sheet and the SOQL resultset, there are several differences. The report shows the number of reports to be cleaned up as 5214 whereas the SOQL shows 5216 reports. When I checked the differences, I could see that the SOQL has pulled some reports that were ran just a few days ago. Below is an example.

enter image description here

My understanding is that if I include the condition LastRunDate != LAST_N_MONTHS:6, the SOQL results should not include any reports that were ran in the last six months.

Am I missing something?

1 Answer 1

0

As per the documentation:

LAST_N_MONTHS:n

Starts at 12:00:00 AM on the first day of the month that started n months before the current month and continues up to 11:59 PM on the last day of the month before the current month.

Which means your SOQL query will include reports run in the current month

1
  • Thanks for your resposne. I have modified the SOQL to include the criteria LastRunDate != THIS_MONTH and LastRunDate != NULL and still the SOQL results are NOT matching with the Salesforce report. Salesforce Report has 5214 records in it and SOQL is showing 5061 records. Aug 17 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .