+ Start a Discussion
Rahul Sherikar 4Rahul Sherikar 4 

Solution to move business logic from trigger to controller only in case of record inserted or updated from visual force page(UI) not for Data loader.

I have a Trigger and workflows on an object.

In trigger for every insert or update certain functionality happens. this functionality is added to trigger mainly because of Data loader(records inserted or updated from data loader).

The issue is, it is causing Too many SOQL for insert or update of records from VF page.

I'm using flag to determine if the insert happing from VF page or data loader, if it is from VF page then execute this functionality only at end of the transaction.

Is there any design or logic which can be used to execute this functionality only once and only at end of the transaction when coming from VF page?
Saravanan @CreationSaravanan @Creation
Hi Rahul,

I would suggent you to have custom setting to control this.

Create a hierarchy Custom Setting  and have a fields call 'Trigger isActive'

In the trigger use the below line before executing any lines

Control__c var= Control__c.getInstance(UserInfo.getUserId());
if(var==nul  ||  var.Trigger_isActive__c==false){
// Trigger code

Rahul Sherikar 4Rahul Sherikar 4
Hi Saravanan,

The issue will still remain correct, this custom setting will be active in org even for record inserted from dataloader or from vf page.

How to differentiate record is inserted from dataloader or vf page? any solution appart  from using flags.
Saravanan @CreationSaravanan @Creation
I thought that the Data loader person will be different from the person who is using the Visualfoce page, But I this case

You can have one check box field on the record. When you are inserting the record from visualforce page you can make the field as checkedand in the trigger you can check whether the checkbox is checked or not and you can avaoid the execution.

Without any flag you can't able to achieve this.

Rahul Sherikar 4Rahul Sherikar 4
Thanks for the reply Saravanan, Yes even I think without any flag we cannot do it but still wanted to know is there any possible way to do it. it looks like there is no other solution.