I have an external application inserting Contact records into the Salesforce (SFDC) instance. Within the external application there is no way to conditionally remove any records from the list so they don't create specific Contacts. If the external application needs to create 100 contacts, they will currently create 100 contacts (we can assume all required fields are set).
As a result, I have to conditionally remove the records as they come into SFDC, but before they get inserted into SFDC.
Question:
How do I conditionally remove records from the beforeInsert event when the external application attempts to insert records?
Goal(s):
- Any Contact where myField__c=false comes in from the external application then do not insert them.
What I tried, but didn't work
trigger ContactTrigger on Contact (Before insert) {
if(Trigger.isInsert) {
Integer numOfRecords = Trigger.new.size();
for(Integer i = 0; i < Trigger.new.size(); i++) {
if(Trigger.new[i].myField == false) {
Trigger.new.remove(i);
}
}
}
}