Monday, 5 June 2023

"Uncommitted Work Pending" error in Salesforce

The "𝐔𝐧𝐜𝐨𝐦𝐦𝐢𝐭𝐭𝐞𝐝 𝐖𝐨𝐫𝐤 𝐏𝐞𝐧𝐝𝐢𝐧𝐠" error is typically encountered when performing database operations, such as DML (Data Manipulation Language) statements or callouts, within the same transaction as a platform event or email sending operation.

 

Salesforce follows a pattern called "ACID" (Atomicity, Consistency, Isolation, Durability) for maintaining data integrity. This means that database changes are committed together or rolled back together to ensure consistency. When a database operation encounters an error, Salesforce automatically rolls back all changes made within that transaction.

 

However, platform events and email sending operations are not part of the ACID transaction. They cannot be rolled back, even if an error occurs in the transaction. This is where the "Uncommitted Work Pending" error comes into play.

 

To resolve this error, you can follow these steps:

 

1.Move the database operations, such as DML statements or callouts, to a point after the platform event or email sending operation.

2.If you need to update data based on a platform event, consider using Apex triggers on the platform event object to perform the necessary database operations separately.

3.If you encounter the error while performing an email sending operation, make sure to separate it from other database operations by using a separate transaction.

Sunday, 14 May 2023

Quick tips to optimize your Salesforce org

 1. Keep your Salesforce org clean and organized by regularly archiving or deleting old data.

2. Use custom settings in Salesforce to store configurable settings that can be easily changed without modifying code.

3. Leverage the power of Salesforce reports and dashboards to gain insights into your data and make data-driven decisions.

4. Optimize your code by using SOQL queries to retrieve only the data you need, rather than retrieving all records and then filtering them in code.

5. Use validation rules in Salesforce to enforce data integrity and ensure that data entered into your org meets your business requirements.

6. Make your Salesforce org more user-friendly by customizing page layouts and creating custom fields and objects.

7. Automate repetitive tasks in Salesforce by using tools like flows to save time and increase efficiency.

8. Improve collaboration and communication within your team by using Salesforce Chatter to share information and collaborate on projects.

9. Use Salesforce mobile app to access your Salesforce data from anywhere, at any time, and keep track of your sales on the go.

10. Keep your Salesforce org secure by implementing two-factor authentication and regularly reviewing user permissions and access.

Best Practices For Large Data Volumes in Salesforce

 Your Org has tens of thousands of users, tens of millions of records, or hundreds of gigabytes of total record storage, have to follow best practices. Few Considerations:


Skinny Tables

Recommended to make your query fast. Important for batches taking long time to execute.


Indexes

Use index fields in where clause of Query. Multiple indexed field in query make it more faster. Even use Two-Column Custom Indexes. Two-column index is more efficient than single indexes on same fields.


Divisions

Partitioning the data of large deployments to reduce the number of records returned by queries and reports. For example, a deployment with many customer records might create divisions called US, EMEA, and APAC to separate the customers into smaller groups that are likely to have few interrelationships.


Mashups

One approach to reducing the amount of data in Salesforce is to maintain large data sets in a different application, and then make that application available to Salesforce as needed.


Deleting Data

Delete unused or unnecessary data. Use Bulk API's hard delete option, which allows records to bypass the Recycle Bin and become immediately available for deletion.


Search

When large volumes of data are added or changed, the search system must index that information before it becomes available for search by all users, and this process might take a long time.


Indexing with Nulls

Idea to reduce Null values, replace with NA or blank. Either use formula field to set value and index formula field.


API Performance

Add addition filter in rest API's query, so they don’t scan all salesforce data.


Sort Optimisation on a Query

Add a limit or sort order in query to make it fast and scan a limit of data only.

Field Trip (ZoomInfo Field Trip App Exchange tool)


Field Trip for Data Analysis and Data Cleansing Process

 

 Field Trip is a free tool on the Salesforce AppExchange that is incredibly simple to use and can empower admins and reveal what fields the team is using. Working through the fields is easier with Field Trip Analysis’ that run against specific objects. Running this analysis gives insight into the following:

  • Identify and remove fields that aren’t used
  • Make important fields required
  • Clean-up Page Layouts
  • Identify what data your users think is valuable

 

Field Trip mainly comprises of two objects namely,

1. Field Trip

2. Field Analyses

In the Field trip object, the user can give the name for field analysis, object API name and the criteria to filter the field for the record. Thus, it will list all the custom and standard fields of the selected object. It also provides the information of the percentage of the field utilization along with record count.

The Field Analyses object contains all the details like Field name, label, Type, PopulateOn and PopulateOn% in which we want to analyze. The Field Analyses (child) object has a master-detail relationship with Field Trip (Parent) object. So, the Field Trip Analyses object details are displayed in the related list of Field Trip object.

It also provides us the facility to generate the field trip reports monthly and current date (today’s date) report. With the help of this report, we can easily find and remove the unused fields of objects in the organization.

 

Pros: 

  1. Easy to analyze the fields for all custom and standard objects fields.
  2. Field trip reports help to analyze the fields which are not used consistently.
  3. No limitation to the number of records or fields to be analyzed.
  4. Analyzing the subset of records by adding filters is possible.
  5. Cleaning up the unused fields in the object.

Cons: 

  1. In the Field Trip, we can’t create the report based on the page layout.
  2. All reports should display all the fields listed on an object.
  3. If we need to analyze the subset of records, then we require an SOQL Query to be built to filter those records.
  4. Field Creation Date is not available on the reports. When a field is created, the field utilization % will be zero. It would be nice if we could pull based on the creation date of the field.

Conclusion : 

This Field Trip Application is very simple and easy to use.This is the best tool for data cleansing  and data analyses process.Report generation helps us to easily find and remove any unused fields in the object.

 


Monday, 1 May 2023

How to Call Apex from Flow using Invocable Action :

 To call Apex from Flow, you need to define the method in your Apex Class as an Invocable Method. And here are some of the rules that you need to follow when using Invocable Method:


  • The Apex class must be defined as public or global.
  • There can be only one invocable method in the Apex class.
  • The invocable method must be static and public or global, and its class must be an outer class.
  • There can be at most one input parameter to Apex method and its data type must be of list type.
  • The data type returned by the method must also be of the list type.

Faster Account Sharing Rules Recalculation (Spring ’23)

 Salesforce provides implicit sharing between a parent account and its child objects (cases, contacts, and opportunities) and creates implicit child share records on these objects.


With Spring ’23 release it is changing the way that automatic sharing calculation works behind the scenes for case and contact objects. Salesforce will no longer store child implicit share records between accounts and their child case and contact records. Instead, the system dynamically determines whether users can access child case and contact records when they try to access them. Not storing the child implicit share records speeds up ownership and sharing rule recalculation for accounts.


To enable this feature, please contact Salesforce Customer Support.


References :

1.https://www.linkedin.com/pulse/faster-account-sharing-recalculations-larry-tung

Monday, 6 March 2023

Sharing Rules Recalculation

 1.Manual Sharing Rule Recalculation (Parallel Calculation)

2.Auto Sharing Rule Recalculation (One by One Calculation)


Manual Sharing Rule Recalculation (Parallel Calculation) :


whenever a sharing rule is recalculated manually, it is always done in parallel meaning all sharing rules calculation 

would start together and would run simultaneously.


If the number of records that are impacted by the recalculation are less than 25k or 25000 then in this case 

you would not receive an email upon completion of the recalculation.


We can track Manual Sharing Recalculation activity in the 'Background Jobs'.

we will find the start time along with the specific sharing criteria , percentage completed and the end time.



Note :

Manual sharing recalculation or parallel recalculation is faster than the Auto Sharing recalculation.


Auto Sharing Rule Recalculation (One by One Calculation) :


The Auto Recalculation of sharing rules is when some activity triggers the modification to the sharing rules and 

so a recalculation is done for the same by Salesforce without explicitly clicking on Recalculate button.


This happens when for example a record type is deleted or there is a change in the Role Hierarchy or any activity 

that sees a modification in the sharing rules. As soon as the activity is performed, Salesforce itselves starts the 

recalculation of the sharing rules for the whole org, this is done in a one by one mode meaning only one sharing rule at a time.


As only one sharing rule is calculated at a time it takes quite a long time depending on your org data.


To get an estimate of how much time would it take to recalculate the Sharing Rules on your org, 

Salesforce suggests that you run the same on a full copy sandbox. Ideally the time taken on the Full Copy sandbox 

is a replica of how much time it would take on your production instance.


Defer Sharing Calculations:


Deferring sharing calculation is ideal if you make a large number of changes to roles, territories, groups, users, 

portal account ownership, or public groups participating in sharing rules, and want to suspend the 

automatic sharing calculation to a later time.