DEV Community

hailports
hailports

Posted on

5 SOQL Queries Every Salesforce Admin Should Run Monthly

5 SOQL Queries Every Salesforce Admin Should Run Monthly

As a senior Salesforce administrator, you know that maintaining and optimizing your Salesforce org is an ongoing task. One of the most powerful tools at your disposal is SOQL (Salesforce Object Query Language), which allows you to retrieve data from your Salesforce organization. Running specific SOQL queries regularly can help you maintain performance, identify inefficiencies, and ensure compliance.

In this article, I'll share five essential monthly SOQL queries that every Salesforce admin should run. These queries will provide insights into critical areas of your org such as object usage, record locking, data quality, and more.

Query 1: Identifying Unused Objects

Unused objects can lead to unnecessary storage costs and maintenance overhead. Running this query helps you identify objects that are no longer in use or have minimal activity.

SELECT Id, Name 
FROM CustomObject 
WHERE LastModifiedDate < LAST_N_DAYS:365 
AND IsActive = true 
ORDER BY CreatedDate ASC;
Enter fullscreen mode Exit fullscreen mode

Steps to Run the Query:

  1. Log into your Salesforce org.
  2. Navigate to Setup > Develop > SOQL/SOSL Queries.
  3. Enter the SOQL query above in the SOQL Editor.
  4. Click "Run".

Review the results and consider deactivating or deleting unused objects if they are no longer needed.

Query 2: Checking for Locking Records

Record locking can impact user experience and application performance, especially during critical business processes like order management or financial transactions. This query helps you identify records that have been locked recently.

SELECT Id, Name, OwnerId, LastModifiedById, 
       LastModifiedDate, IsLocked 
FROM Account 
WHERE IsLocked = true AND 
      LastModifiedDate >= YESTERDAY;
Enter fullscreen mode Exit fullscreen mode

Steps to Run the Query:

  1. Follow steps 1-3 from Query 1.
  2. Enter the SOQL query above in the SOQL Editor.
  3. Click "Run".

Review the results and investigate any records that are locked recently. Consider unlocking them if they can be safely released.

Query 3: Verifying Data Quality

Data quality is crucial for maintaining accurate reports and ensuring compliance. This query helps you identify duplicate or invalid records in your org.

SELECT Id, Name, Email 
FROM Contact 
WHERE Email = '' OR Email LIKE '%@%.%';
Enter fullscreen mode Exit fullscreen mode

Steps to Run the Query:

  1. Follow steps 1-3 from Query 1.
  2. Enter the SOQL query above in the SOQL Editor.
  3. Click "Run".

Review the results and take action to clean up or correct any invalid records.

Query 4: Monitoring Large Data Volumes

Large data volumes can impact performance, particularly when performing bulk operations. This query helps you identify objects with a high number of records that might need optimization.

SELECT Name, (SELECT COUNT() FROM RelatedObject__c) 
FROM CustomObject 
GROUP BY Name 
ORDER BY COUNT(RelatedObject__c) DESC LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

Steps to Run the Query:

  1. Follow steps 1-3 from Query 1.
  2. Enter the SOQL query above in the SOQL Editor.
  3. Click "Run".

Review the results and consider optimizing or archiving objects with a high number of related records.

Query 5: Checking for Unnecessary Relationships

Unnecessary relationships can lead to data redundancy and increased storage costs. This query helps you identify relationships that might be unnecessary.

SELECT Id, Name 
FROM CustomObject__c 
WHERE MasterLabel = 'Parent Object' AND 
      (SELECT COUNT() FROM ChildRelationship_Name__r) = 0;
Enter fullscreen mode Exit fullscreen mode

Steps to Run the Query:

  1. Follow steps 1-3 from Query 1.
  2. Enter the SOQL query above in the SOQL Editor.
  3. Click "Run".

Review the results and consider removing or archiving unnecessary relationships.

Conclusion

Running these monthly SOQL queries can help you maintain a healthy Salesforce org, optimize performance, and ensure data quality. By regularly monitoring your org through these queries, you can proactively address issues before they become critical.

Try the Free Scanner

To further enhance your Salesforce org maintenance, try the free scanner at https://orgscanner.dev/?utm_source=devto&utm_medium=content&utm_campaign=free_blitz. Org Scanner provides automated insights and recommendations to help you optimize your Salesforce org.

By integrating these practices into your monthly maintenance routine, you can keep your Salesforce org running smoothly and efficiently.

Top comments (0)