You need to sign in to do that
Don't have an account?
Simple Trigger and Method help needed
I need to take a trigger and move it into a class method. The trigger works correctly, but I need to move it into a method and call it from 2nd trigger that is already calling other methods. I'm doing this because I don't want multiple triggers on one object.
What should the method look like?
trigger dealUpdate on Deal_Update__c (before insert)
{
set<string> bpidSet = new set<string>();
for (Deal_Update__c spBPID : Trigger.new){
if(spBPID.Partner_BPID__c!=null) bpidSet.add(spBPID.Partner_BPID__c);
}
if(bpidSet.size()>0){
List<Account> accountList = [SELECT Id, SP_BPD__c FROM Account
WHERE SP_BPD__c = :bpidSet AND IsPersonAccount=FALSE
AND RecordType.DeveloperName='Partner_Account'];
Map<string,id> accountmap = new Map<string,id>();
for (Account a : accountList) {
accountmap.put(a.SP_BPID__c,a.id);
}
for (Deal_Update__c spBPID : Trigger.new){
if(accountmap != null) {
spBPID.Partner_Account__c = accountmap.get(spBPID.Partner_BPID__c);
}
}
}
}
What should the method look like?
trigger dealUpdate on Deal_Update__c (before insert)
{
set<string> bpidSet = new set<string>();
for (Deal_Update__c spBPID : Trigger.new){
if(spBPID.Partner_BPID__c!=null) bpidSet.add(spBPID.Partner_BPID__c);
}
if(bpidSet.size()>0){
List<Account> accountList = [SELECT Id, SP_BPD__c FROM Account
WHERE SP_BPD__c = :bpidSet AND IsPersonAccount=FALSE
AND RecordType.DeveloperName='Partner_Account'];
Map<string,id> accountmap = new Map<string,id>();
for (Account a : accountList) {
accountmap.put(a.SP_BPID__c,a.id);
}
for (Deal_Update__c spBPID : Trigger.new){
if(accountmap != null) {
spBPID.Partner_Account__c = accountmap.get(spBPID.Partner_BPID__c);
}
}
}
}
All Answers
Trigger
Handler class
Please check below post for trigger framwork
1) http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Let us know if this will help you
Thanks
Amit Chaudhary
[OPERATION FAILED]: triggers/DealUpdate.trigger: Variable does not exist: new (Line: 5, Column: 9)
My trigger is below:
trigger DealUpdate on Deal_Update__c (before update, before insert) {
if(Trigger.isInsert){
new dealUpdateTriggerHandler().dealUpdateAction(true, trigger.new, null);
new.dealUpdateTriggerHandler().OnBeforeInsert(trigger.new);
}
if(Trigger.isUpdate){
new dealUpdateTriggerHandler().dealUpdateAction(false, trigger.new, trigger.oldmap);
}
}
handler.OnBeforeInsert(trigger.new);
Error: Method does not exist or incorrect signature (List<Deal_Update__c> newDealUpdate)