2

The trigger must be developed. Inside I need to check are records came from outside SF via bulk load or they are created internally?

I can not change uploading process or modify records before they are uploaded.

All checks must be done inside a trigger.

How I can achieve this?

Thanks.

2 Answers 2

4

I suggest that you create a specific User for this bulk load process that is not used for any other purpose. Then your trigger can base its conditional logic on that:

if (UserInfo.getUserName() == 'bulkloadprocess@abc.com')) ...
2
  • Good advice, but imagine this trigger will be a part of a managed package. Also there will be a settings checkbox. If its checked then all bulk loaded records should be processed by the trigger, internal records not. if not checked then all records should not be processed by a trigger. Actually i can use this solution, and add setting for the user which will be used for loading records. Maybe we can find easier solution. May 6, 2016 at 15:04
  • @DenisPereverzev Yes the custom setting could be the name or ID of the User that is special cased; if not set there would be no special casing.
    – Keith C
    May 6, 2016 at 16:09
2

When you generally load data from outside using Dataloader it runs in a batch.

So the check you can apply is-

    if(System.isBatch()){
       //do this
    }else{
       //do this
    }

Note: If there are batches inside the system which are also making triggers run.Then also the code inside this condition will run.

2
  • @Frodo - Will Syste.isBatch=TRUE, If I am performing a DML operation on a list of records using apex.. or will it be true only if I perform Batch Job
    – kso
    May 6, 2016 at 8:13
  • 1
    @KAADI it will be true when this code executes from batch..
    – Ratan Paul
    May 6, 2016 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.