You need to sign in to do that
Don't have an account?
Rahul 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?
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?
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
}
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.
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.