You need to sign in to do that
Don't have an account?
Trigger not Working as expected
Posted on Apex board as well, kind of need help as soon as possible Please? :)
Hello,
I have a trigger that is supposed to update the Contact of a case that is closed:
trigger setLastSurveySentDate on Case (after insert) {
Map<Id,Id> contactToCaseMap = new Map<Id,Id>();
for(Case A : trigger.new)
contactToCaseMap.put(A.ContactId,A.Id);
List<Contact> contactsToUpdate = new List<Contact>{};
for (Contact con: [SELECT Id,Last_Survey_Sent_Date__c FROM Contact WHERE Id IN: contactToCaseMap.keySet()]) {
Id caId = contactToCaseMap.get(con.Id);
Case ca = trigger.newMap.get(caId);
if (ca.Status=='Closed' && con.Last_Survey_Sent_Date__c < date.today()-90 ){
con.Last_Survey_Sent_Date__c=date.today();
contactsToUpdate.add(con);
}
else if (ca.Status=='Closed' && con.Last_Survey_Sent_Date__c == null ){
con.Last_Survey_Sent_Date__c=date.today();
contactsToUpdate.add(con);
}
}
if(contactsToUpdate != null && !contactsToUpdate.isEmpty())
Database.update(contactsToUpdate);
}
I have a workflow that sends a survey, updates the case Last Survey Sent Date case field, and records a task that the survey was sent, as long as the Contact has not received a survey within the last 90 days:
OR( today() - DATEVALUE(Contact.Last_Survey_Sent_Date__c) >= 90,isBlank(Contact.Last_Survey_Sent_Date__c))
The trigger is updating the contact field, however, it is not using the date that has been updated on the case.
The date of survey sent CASE = 09/03/2013 12:15 AM
The date of survey sent CONTACT = 09/02/2013 8:00 PM
The date of survey sent on the contact is always the same time and the date changes depending on the real time of day (e.g. tests performed prior to 12 AM showed a date of 09/02/2013 8:00 PM)
Just bumping up. Please help?
But... your problem is on the trigger execution or the workflow, i did not get that.
cheers
Solved in other catagory, this is a duplicate post to:
http://boards.developerforce.com/t5/Apex-Code-Development/Can-anyone-help-determine-why-trigger-is-not-working/m-p/673689