• London Calling.ax1696
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi,

 

In essence the below trigger creates records in two junction objects, TrialContactAssociation__c & TrialAccountAssociation__c , when a Trial__c record is created that matches an email address in an existing Contact.  This creates a way for us to track Accounts and Contacts that are already in our system for incoming trials.

 

After a zillion hours of Googling I can't seem to figure out how to reference Email__c outside the for loop?

 

Any help on the bulkification syntax will be greatly appreciated!  All bulkification examples I've come across reference the ID as opposed to a 'column' of incoming records.

 

trigger TrialInsert on Trial__c (after insert) {
    
    List<TrialContactAssociation__c> ContactListItem = new List<TrialContactAssociation__c>();
    List<TrialAccountAssociation__c> AccountListItem = new List<TrialAccountAssociation__c>();
    
    for (Trial__c c : Trigger.new) {
        
        List<Contact> contactID = new List<Contact>([SELECT Id FROM Contact WHERE Email LIKE :c.Email__c]);
        List<Contact> ContactAccountRel = new List<Contact>([SELECT AccountId FROM Contact WHERE Email LIKE :c.Email__c]);

        for (Contact contactItem : contactID){
            TrialContactAssociation__c clt = new TrialContactAssociation__c(Trial__c = c.ID, Contact__c = contactItem.Id);
            ContactListItem.add(clt);        
        }
        for (Contact AccountItem : ContactAccountRel){
            TrialAccountAssociation__c clt2 = new TrialAccountAssociation__c(Trial_Account_Asso__c = c.ID, Account_Trial_Link__c = AccountItem.AccountId);
            AccountListItem.add(clt2);
        }    
    }
    insert ContactListItem;
    insert AccountListItem;
}

 Thanks

 

John

Hi,

 

In essence the below trigger creates records in two junction objects, TrialContactAssociation__c & TrialAccountAssociation__c , when a Trial__c record is created that matches an email address in an existing Contact.  This creates a way for us to track Accounts and Contacts that are already in our system for incoming trials.

 

After a zillion hours of Googling I can't seem to figure out how to reference Email__c outside the for loop?

 

Any help on the bulkification syntax will be greatly appreciated!  All bulkification examples I've come across reference the ID as opposed to a 'column' of incoming records.

 

trigger TrialInsert on Trial__c (after insert) {
    
    List<TrialContactAssociation__c> ContactListItem = new List<TrialContactAssociation__c>();
    List<TrialAccountAssociation__c> AccountListItem = new List<TrialAccountAssociation__c>();
    
    for (Trial__c c : Trigger.new) {
        
        List<Contact> contactID = new List<Contact>([SELECT Id FROM Contact WHERE Email LIKE :c.Email__c]);
        List<Contact> ContactAccountRel = new List<Contact>([SELECT AccountId FROM Contact WHERE Email LIKE :c.Email__c]);

        for (Contact contactItem : contactID){
            TrialContactAssociation__c clt = new TrialContactAssociation__c(Trial__c = c.ID, Contact__c = contactItem.Id);
            ContactListItem.add(clt);        
        }
        for (Contact AccountItem : ContactAccountRel){
            TrialAccountAssociation__c clt2 = new TrialAccountAssociation__c(Trial_Account_Asso__c = c.ID, Account_Trial_Link__c = AccountItem.AccountId);
            AccountListItem.add(clt2);
        }    
    }
    insert ContactListItem;
    insert AccountListItem;
}

 Thanks

 

John