2

I want to run the trigger only when the records are inserted through data loader not when records are created through UI or records are created through other trigger.Is there a way to do this

4 Answers 4

3

You could add a custom checkbox field which is hidden from the pagelayout.

  • This field could be mapped to always insert as "true" with dataloader.
  • Make your after insert trigger only execute conditionally on this field to be true.
  • Optionally have your trigger set the field to false, or you could keep it as true to see that these records were imported through data loader.
1
5

The way we handled this recently was to set a boolean on the records called "From_Import__c" and only set that to true when loading in from the dataloader (in our case it was through Jitterbit ETL)

3

Through "other trigger" you can do by using a static variable:

public class PreventTrigger {
    public static Boolean forNow = false;
}

trigger A on A (after insert) {
    PreventTrigger.forNow = true;
    // logic to get to B trigger
    insert b;
}

trigger B on B (after insert) {
    if(PreventTrigger.forNow) {
        return;
    }
    // Rest of logic
}

For updating "only through the data loader", you need a field that you can specify as hidden to users, but available in the data loader, such as a checkbox field. There's no way accurately to detect if an action came from the UI or from the Data Loader otherwise.

1

The best way to handle this is to create a custom setting, name it background job and then enter a login account like [email protected]. Then in your trigger code check if the user executing matches the custom setting background job user.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .