How to remove some records from a before insert Trigger.new list when the DML is simple Insert operation. - Answers - Salesforce Trailblazer Community
Ask Search:
Aladin BanwalAladin Banwal 

How to remove some records from a before insert Trigger.new list when the DML is simple Insert operation.

Hello everyone,
Our clients are using the Zynbit tool to generate tasks from the email received on their email account which is managed package. The Zynbit tool has a simple insert statement without AllOrNone while inserting tasks in bulk. Now I need to stop generating tasks that have "OOO" or "Out of Office" subject in bulk operation.
The custom validation rule or addError in Trigger is working only when a single task gets inserted. But I need to handle it on a bulk operation without changing anything in the Zynbit tool. How can I do it?
Please help me with this issue. Thanks in advance.
Best Answer chosen by Aladin Banwal
Tommaso BolisTommaso Bolis
You can't do it.
You could mark them as to be deleted and then schedule a delete of these records.
You can also make marked records not visible.

All Answers

Tommaso BolisTommaso Bolis
You can't do it.
You could mark them as to be deleted and then schedule a delete of these records.
You can also make marked records not visible.
This was selected as the best answer
Aladin BanwalAladin Banwal
Thank you Tommaso, for your response.
Is there any way in which we can modify the insert statement before it applies from other transactions?
Tommaso BolisTommaso Bolis
Hi Aladin,
if you mean in terms of field values, the right place do it is before trigger.

If you want avoid insert the only option is "AddError", but in your case all records would be rollbacked.
Aladin BanwalAladin Banwal
Thank you Tommaso, That helped a lot.