You need to sign in to do that
Don't have an account?
FabianG
Bulkify cross object field update trigger on multiple fields
Dear Salesforce guru's,
I'm currently facing some struggle bulkifiying a cross object update trigger that should update multiple fields.
Background:
I want checkboxes on leads object to be checked, when a date field on a custom object called "Suchprofil" is populated. But there are in total 6 date fields and checkboxes on the same objects. The objects share the same ID (which is actually stored as a string)
The simple trigger on a single field works fine and looks as follows:
Unfortunately I'm not really familiar wih mapping yet. I tried to build a bulkified trigger on the basis of David Liu's example http://www.sfdc99.com/2014/01/25/use-maps-navigate-across-lists/
Here's what I made up so far:
Can anyone help me to correctly map the date fields on the custom object to activate the corresponding checkboxes on the lead object?
I really appreciate your help!
Thanks
Fabian
I'm currently facing some struggle bulkifiying a cross object update trigger that should update multiple fields.
Background:
I want checkboxes on leads object to be checked, when a date field on a custom object called "Suchprofil" is populated. But there are in total 6 date fields and checkboxes on the same objects. The objects share the same ID (which is actually stored as a string)
The simple trigger on a single field works fine and looks as follows:
trigger updateActivatedFieldLead on Suchprofil__c(before insert, before update) { List<Lead> leadList = new List<Lead>(); List<String> companyId = new List<String>(); for(Suchprofil__c sp : Trigger.new) { if(sp.Aktivierungsdatum__c!=null) { companyId.add(sp.UnternehmensID__c); } } leadList = [SELECT Id, Activated__c FROM Lead WHERE UnternehmensID__c IN : companyId]; for(Lead l : leadList) { l.Activated__c = true; } update leadList; }
Unfortunately I'm not really familiar wih mapping yet. I tried to build a bulkified trigger on the basis of David Liu's example http://www.sfdc99.com/2014/01/25/use-maps-navigate-across-lists/
Here's what I made up so far:
trigger SPLead on Suchprofil__c (before insert, before update){ Set<String> allSP = new Set<String>(); for (Suchprofil__c NewSP : Trigger.new){ if (newSP.Aktivierungsdatum__c != null || // Mail_versendet__c != null || Mail_ge_ffnet__c != null || RecruiterPINDashboardAccess__c != null || RecruiterPINDashboardAccessSuccess__c != null || Deaktivierungsdatum__c != null){ allSP.add(newSP.UnternehmensID);} } List<Lead> CLeads = [SELECT Id, Activated__c, Mail_versendet__c, Mail_ge_ffnet__c, Mail_geklickt__c, Eingeloggt__c, Deaktiviert__c FROM Lead WHERE UnternehmensID IN : NewSP]; Map<String, Lead> SPtoLead = new Map<String, Lead>(); for (Lead L : CLeads){ SPtoLead.put(L.UnternehmensID, L); } for (Suchprofil__c NewSP : Trigger.new){ if (newSP.Aktivierungsdatum__c != null){ Lead a = SPtoLead.get(newSP.UnternehmensID); a.Activated__c = true } } //Rest of the mapping }
Can anyone help me to correctly map the date fields on the custom object to activate the corresponding checkboxes on the lead object?
I really appreciate your help!
Thanks
Fabian
FabianG
Unfortunately, I can't edit my post. There were some slight mistakes, I could identify so far:
FabianG
Push