• FabianG
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
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:
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
Dear all,

I'm trying to develop an apex trigger that populates a checkbox-field on a standard object if a date-field on a custom object is populated/not empty.
Due to a missing/variable relationship this can't be done using a workflow. Both objects have a unique company-id in common which coult be used to relate them to each other.
I know more or less that I have to build a list in the trigger to retrieve the id's and map them but I can' figure out how to to write a working trigger.

Custom object: SProfile__c
Custom object date-field: ActivationDate__c
Standard object: Lead
Standard object checkbox: Activated__c
Matching ID: CompanyID__c

I hope the information helps. I very much appreciate your help!

Cheers
Fabian

 
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:
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
Dear all,

I'm trying to develop an apex trigger that populates a checkbox-field on a standard object if a date-field on a custom object is populated/not empty.
Due to a missing/variable relationship this can't be done using a workflow. Both objects have a unique company-id in common which coult be used to relate them to each other.
I know more or less that I have to build a list in the trigger to retrieve the id's and map them but I can' figure out how to to write a working trigger.

Custom object: SProfile__c
Custom object date-field: ActivationDate__c
Standard object: Lead
Standard object checkbox: Activated__c
Matching ID: CompanyID__c

I hope the information helps. I very much appreciate your help!

Cheers
Fabian