An open API service indexing awesome lists of open source software.

https://github.com/rpdevjesco/salesforceerrorutility


https://github.com/rpdevjesco/salesforceerrorutility

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

![image](https://github.com/RPDevJesco/SalesforceErrorUtility/assets/8800044/25a8d296-041c-4fe9-9cbf-2f9382c5a5d4)

The code provided consists of two classes: LogUtility and GovernorLimitsUtil. Here's a breakdown of their functionalities and use cases:
LogUtility Class

This class is designed for logging errors and exceptions that occur in Salesforce Apex code. It has several methods, each serving a specific purpose:

logDMLErrors Method:
Purpose: Logs errors encountered during DML (Data Manipulation Language) operations like insert, update, or delete.
Parameters:
List results: The results from a DML operation, containing success/failure information for each record.
SObject so: The Salesforce object involved in the DML operation.
Functionality: Iterates over each SaveResult, checks for errors, and creates an ErrorLog__c record for each error. It includes the error message, the type of SObject, and the record ID. It also appends the governor limits report to each error log.
Use Case: Useful for capturing specific errors that occur during DML operations, allowing for detailed analysis and debugging.

logException Method:
Purpose: Logs exceptions that are thrown within Apex code.
Parameters:
Exception ex: The caught exception.
SObject so: The Salesforce object related to where the exception occurred.
Functionality: Creates a single ErrorLog__c record with details of the exception, including the message, stack trace, and governor limits report.
Use Case: Ideal for catching and logging unhandled exceptions, providing insights into unexpected failures in the code.

GovernorLimitsUtil Class

This class is a utility for generating reports on Salesforce governor limits. It contains several methods, each generating a report on different categories of governor limits:

Methods like getSOQLReports, getSOSLReports, getDMLRecordProcessingReports, etc.:
Purpose: Each method generates a report on specific governor limit usage, such as SOQL queries, SOSL queries, DML operations, etc.
Functionality: These methods use Salesforce's Limits class to retrieve current usage against the set governor limits in their respective categories.
Use Case: These methods are useful for monitoring and debugging, helping to understand how close the code is to hitting Salesforce's governor limits in various aspects.

getApexResourceUsageReports Method:
Purpose: Generates a combined report on common Apex resource usage governor limits.
Functionality: Concatenates reports from selected categories relevant to common Apex usage.
Use Case: Provides a quick overview of the most relevant governor limits for a typical Apex transaction.

getLimitsReport Method:
Purpose: Generates a comprehensive report on all Salesforce governor limits.
Functionality: Concatenates reports from all categories covered by the utility.
Use Case: Offers a complete view of all governor limits usage, ideal for thorough debugging and performance monitoring.

Overall Use Case

The LogUtility class, enhanced with governor limits reporting from GovernorLimitsUtil, is an excellent tool for in-depth error and exception tracking in Salesforce. By including governor limits reports in the error logs, developers can correlate errors with potential governor limits issues, leading to more effective troubleshooting and optimization of Apex code. This is especially valuable in complex Salesforce implementations where understanding resource consumption is crucial for maintaining system stability and performance.