• Chitiz Agarwal
  • NEWBIE
  • 0 Points
  • Member since 2013
  • Kumar

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi , 
I have a trigger to get the fields from Child object to parent object and i was able to succesfullt get all the information i need . Only part i was missing is when i try to get the recently created record created date it gives me the oldest (first created record ) . 
trigger ContactAlerts on ET4AE__IndividualEmailResult__c (after insert, after update) {

Map<ID, Contact> ConToUpdate = new Map<ID, Contact>();   
List<Id> listIds = new List<Id>();
Boolean isExists = false;

list<ET4AE__IndividualEmailResult__c> EmailList = new list<ET4AE__IndividualEmailResult__c>();

for (ET4AE__IndividualEmailResult__c childObj : Trigger.new){
listIds.add(childObj.ET4AE__Contact__c);
}


ConToUpdate = new Map<Id, Contact>([SELECT id, ET_Clicked_Atleat_Once__c ,ET_Hard_bounce__c,ET_Unsubscribed__c,(SELECT ID,CreatedDate,ET4AE__DateUnsubscribed__c, ET4AE__HardBounce__c,ET4AE__NumberOfTotalClicks__c  FROM ET4AE__IndividualEmailResults__r) FROM Contact WHERE ID IN :listIds]);


for (Contact Con: ConToUpdate.values()){
isExists = false;
for(ET4AE__IndividualEmailResult__c  IER :Con.ET4AE__IndividualEmailResults__r){
 if(IER.ET4AE__NumberOfTotalClicks__c == 1){
  Con.ET_Clicked_Atleat_Once__c = 1;
  isExists = true;
  }
  if(isExists == false)
  {
  Con.ET_Clicked_Atleat_Once__c = 0;
 }  
 if(IER.ET4AE__HardBounce__c == True){
 Con.ET_Hard_bounce__c = true;
 }
  if(IER.ET4AE__DateUnsubscribed__c != null){
 Con.ET_Unsubscribed__c = true;
 }
 if(IER.CreatedDate != null){
 Con.ET_Last_Email_Sent_date__c = IER.CreatedDate;
 }
 
}
}
Thanks,
Akhil
 
  • December 11, 2014
  • Like
  • 0

I am looking for a method to backup the code for a visualforce page and controller.  If it could do it once a day that would be ok.  If it did it on a button click that would be great also.  Is there anything out there that can do that, or is there a way I can write an apex code to do it?