function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yadhagu LYadhagu L 

what are the possibilities that trigger will skip the records while processing bulk data

In SF org the contact records are come through dataloader, Pardot or any third parties tools. Currently, I have witten apex trigger on contact object to follow unique id for each contacts in org, So I would like to confirm is there any possibilities that trigger will skip or fail due to bulk processing of before or after insertion operation. If trigger fails there is a possibilities that the unique number will skip few series. Could any face this issue let me know, Thanks
Best Answer chosen by Yadhagu L
InzamamulInzamamul (Salesforce Developers) 
Hello Yadhagu,

There is a possibility that an Apex trigger could skip records while processing bulk data. This can happen for a few reasons:

1)Governor limits: Salesforce triggers can be subject to governor limits, such as the number of queries or DML statements that can be executed in a single transaction. If a trigger exceeds a governor limit, it will fail and some records may be skipped.

2)Asynchronous processing: Salesforce triggers can be executed synchronously or asynchronously. Synchronous triggers execute immediately after the record is inserted or updated, while asynchronous triggers execute in the background. If a trigger is asynchronous, it is possible that some records will be processed by the trigger before others. This could lead to skipped records if the trigger fails or is unable to process all of the records in the bulk operation.

3)System errors: It is also possible for Salesforce triggers to fail due to system errors, such as database timeouts or hardware failures. If a trigger fails, some records may be skipped.

To minimize the risk of records being skipped by a trigger, you can do the following:

Use asynchronous triggers: Asynchronous triggers are less likely to be affected by governor limits or system errors.

Batch process records: If you are processing a large volume of records, you can batch them into smaller groups and process them one group at a time. This will reduce the risk of the trigger failing.

Use a queue: You can also use a queue to process bulk data. This will allow you to process the records in the background and avoid governor limits.


You can check for more information with the help of the below article:

https://help.salesforce.com/s/articleView?id=sf.loader_using_bulk_api.htm&type=5

Please mark this as a best answer if this helps.

Thank You!

All Answers

InzamamulInzamamul (Salesforce Developers) 
Hello Yadhagu,

There is a possibility that an Apex trigger could skip records while processing bulk data. This can happen for a few reasons:

1)Governor limits: Salesforce triggers can be subject to governor limits, such as the number of queries or DML statements that can be executed in a single transaction. If a trigger exceeds a governor limit, it will fail and some records may be skipped.

2)Asynchronous processing: Salesforce triggers can be executed synchronously or asynchronously. Synchronous triggers execute immediately after the record is inserted or updated, while asynchronous triggers execute in the background. If a trigger is asynchronous, it is possible that some records will be processed by the trigger before others. This could lead to skipped records if the trigger fails or is unable to process all of the records in the bulk operation.

3)System errors: It is also possible for Salesforce triggers to fail due to system errors, such as database timeouts or hardware failures. If a trigger fails, some records may be skipped.

To minimize the risk of records being skipped by a trigger, you can do the following:

Use asynchronous triggers: Asynchronous triggers are less likely to be affected by governor limits or system errors.

Batch process records: If you are processing a large volume of records, you can batch them into smaller groups and process them one group at a time. This will reduce the risk of the trigger failing.

Use a queue: You can also use a queue to process bulk data. This will allow you to process the records in the background and avoid governor limits.


You can check for more information with the help of the below article:

https://help.salesforce.com/s/articleView?id=sf.loader_using_bulk_api.htm&type=5

Please mark this as a best answer if this helps.

Thank You!
This was selected as the best answer
Yadhagu LYadhagu L
Hi Inzamamul,

Thanks for the suggestion, I have planned to write a batch class to run on 1 hour interval through schedule apex method. thanks