i have scenario like write a trigger avoid insertion of records from data loader,only manual insertion trigger will fire?on any object
while Entering records from data loader trigger should not fire?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityi have scenario like write a trigger avoid insertion of records from data loader,only manual insertion trigger will fire?on any object
while Entering records from data loader trigger should not fire?
To me, this does seem like a valid requirement. Few years back I too asked a similar question.
Making context-aware application are sometimes needed. This is one such use case.
Yes, You can get this done. The trick is to look in URL of the request. Everything in SF happening will have a request.
So I just wrote a trigger on a Custom Object to see, if we can find a pattern in this and use it to our advantage.
trigger MyObjectTrigger on MyObject__c(before insert) {
SYstem.debug(Url.getCurrentRequestUrl().toExternalForm());
}
Then I run certain tests:
Insert Record in SF Classic:
DEBUG : https://mydomain.salesforce.com/a2F/e
In Lightning:
DEBUG : https://mydomain.my.salesforce.com/aura?r=25&ui-force-components-controllers-recordGlobalValueProvider.RecordGvp.saveRecord=1
In Execute Anon:
DEBUG : https://mydomain.my.salesforce.com/services/data/v45.0/tooling/executeAnonymous/?anonymousBody=Insert+new+MyObject__c%28%29%3B&_=1553015078234
In DataLoader:
DEBUG : https://mydomain.my.salesforce.com/services/Soap/s/45.0/00D260000008529
Finally In Dataloader using Bulk API:
DEBUG : http://mydomain.my.salesforce.com/mockRequest/bulkapi/process/00D260000001895/75026000004gcSI/75126000004DSH7
So, technically yes, You can disable insert by DataLoader by checking the if requestURL contains /Soap/s/
or bulkapi
RestContext.request != null
Oct 21, 2019 at 15:34
You can remove the access to data loader by disabling API permission to that user's profile which is not supposed to use Data loader to insert records.
for more details please refer the link
Other option can be like you can create a custom setting with some Flag Field value like true and false. When you want to insert via data loader, then make it false and after loading make it true. In trigger, make sure code will run only when that Flag is true.