+ Start a Discussion
Aidel BruckAidel Bruck 

Date jumping to the next day

Hi, 
I have a trigger that has the following assignment service.Service_Termination_Date__c = comReview.Final_Approval_End_Date__c;
when Final_Approval_End_Date__c;= 12/31/21
the service.Service_Termination_Date__c= 1/1/22
Why does this happen?
 
PriyaPriya (Salesforce Developers) 

Hi Aidel,

Can you provide the entire method or trigger to check it ? 

Also check if there any other process updating the date field.

Regards,

Priya Ranjan

Aidel BruckAidel Bruck
ComReview is a custom related object to opportunities When a certain criteria is met on the related field I want a date field on the opportunity to update to a date field on the related object. Here is the trigger code. The relevant lines are towards the bottom. trigger ReviewInsertUpdate on Review__c (after insert, after update) { // Resolve Record Types ,and Insert to maps ( by Name, By Id ) List rts = [SELECT id, Name FROM RecordType WHERE sObjectType = 'Review__c']; Map rtsMapByName = new Map(); Map rtsMap = new Map(); for(RecordType rt : rts){ rtsMap.put(rt.id,rt); rtsMapByName.put(rt.Name,rt); } List reviews = new List(); Set oppsIds = new Set(); Set oppsIds2 = new Set(); if(trigger.isInsert) for(Review__c rev : trigger.new) { if(rtsMap.get(rev.RecordTypeId).Name == 'Committee Review' && (rev.Status__c == 'Approved' || rev.Status__c == 'Denied')) { Reviews.add(rev); oppsIds.add(rev.Service__c); } else if(rtsMap.get(rev.RecordTypeId).Name == 'Committee Review' && rev.Status__c == 'sent to committee') { oppsIds2.add(rev.Service__c); } } if(trigger.isupdate) for(review__C revold: trigger.old) for(Review__c rev : trigger.new) { if(rtsMap.get(rev.RecordTypeId).Name == 'Committee Review' && (rev.Status__c == 'Approved' || rev.Status__c == 'Denied') && rev.id== revold.id && rev.Status__c!= revold.status__c) { Reviews.add(rev); oppsIds.add(rev.Service__c); } else if(rtsMap.get(rev.RecordTypeId).Name == 'Committee Review' && rev.Status__c == 'sent to committee' && rev.id==revold.id && rev.Status__c== revold.Status__c) { oppsIds2.add(rev.Service__c); } } // Get All Relevant Services List Services = [SELECT id, Policy_Approved__c, Approval_Expiration_Countdown__c, Service_Termination_Date__c, Next_Expected_Review_Type__c, Approval_Expiration_Date__c, Service_Start_Date__c, Approved_Amount__c, Medical_Status__c, Diagnosis__c, CloseDate, Inactive_Reason__c, StageName FROM Opportunity WHERE id IN :oppsIds]; Map servicesMap = new Map(); // Add to Service Map for(Opportunity service : Services){ servicesMap.put(service.id,service); } System.debug('Processing Reviews'); system.debug('Number: '+reviews.size()); // Set Service Stage as the Status of the Review , under the for(Review__c rev : reviews){ Opportunity service = servicesMap.get(rev.service__c); service.stageName = rev.Status__c; } List ClinicalReviews = [SELECT id,LastModifiedDate,Next_Expected_Review_Type_If_Any__c, service__c, createdDate, status__c, Diagnosis__c, Medical_Condition__c FROM Review__c WHERE Service__c IN :oppsIds AND RecordTypeId = :rtsMapByName.get('Clinical Review').id]; Map clinicalReviewsMap = new Map(); for(Review__c rev : clinicalReviews){ if(clinicalReviewsMap.containsKey(rev.service__c)){ Review__c oldrev = clinicalReviewsMap.get(rev.service__c); if(oldrev.LastModifiedDate < rev.LastModifiedDate) clinicalReviewsMap.put(rev.service__c,rev); } else{ clinicalReviewsMap.put(rev.service__c,rev); } } List committeeReviews = [SELECT id,LastModifiedDate,Next_Expected_Review_Type_If_Any__c, service__c, createdDate, status__c, Final_Approval_Amount__c, Final_Approval_Effective_Date__c, Next_Expected_Review_Type__c, Final_Approval_End_Date__c, Approval_Expiration_Countdown__c, Policy_Approved__c, Approved_Policy__c, Related_Insurance_Review__r.Policy_Requesting_Approval__c, Related_Insurance_Review__c FROM Review__c WHERE Service__c IN :oppsIds AND RecordTypeId = :rtsMapByName.get('Committee Review').id]; Map committeeReviewsMap = new Map(); for(Review__c rev : committeeReviews){ if(committeeReviewsMap.containsKey(rev.service__c)){ Review__c oldrev = committeeReviewsMap.get(rev.service__c); System.debug('oldrev.LastModifiedDate->'+oldrev.LastModifiedDate); System.debug('rev.LastModifiedDate->'+rev.LastModifiedDate); System.debug('oldrev.LastModifiedDate < rev.LastModifiedDate->'+(oldrev.LastModifiedDate < rev.LastModifiedDate)); if(oldrev.LastModifiedDate < rev.LastModifiedDate) committeeReviewsMap.put(rev.service__c,rev); } else{ committeeReviewsMap.put(rev.service__c,rev); } } List committeeReviews2 = [SELECT id,LastModifiedDate,Next_Expected_Review_Type_If_Any__c, Final_Approval_Effective_Date__c, Service__c, createdDate FROM Review__c WHERE Service__c IN :oppsIds AND RecordTypeId = :rtsMapByName.get('Committee Review').id AND Review_Type__c = 'New Application']; Map newAppReviewsMap = new Map(); for(Review__c rev : committeeReviews2){ if(newAppReviewsMap.containsKey(rev.service__c)){ Review__c oldrev = newAppReviewsMap.get(rev.service__c); if(oldrev.LastModifiedDate < rev.LastModifiedDate) newAppReviewsMap.put(rev.service__c,rev); } else{ newAppReviewsMap.put(rev.service__c,rev); } } for(Opportunity service : services){ system.debug('For opportunity with id: '+service.id); Review__c comReview = committeeReviewsMap.get(service.id); Review__c cliReview = clinicalReviewsMap.get(service.id); Review__c newAppReview = newAppReviewsMap.get(service.id); system.debug('Committee review id: '+comReview.id); system.debug('Clinical review id: '+cliReview.id); if(newAppReview != null) system.debug('New App review id: '+newAppReview.id); if(comReview.status__c == 'Denied') service.Inactive_Reason__c = 'Not Elegible'; service.CloseDate = Date.today(); service.Diagnosis__c = cliReview.Diagnosis__c; service.Medical_Status__c = cliReview.Medical_Condition__c; service.Approved_Amount__c = comReview.Final_Approval_Amount__c; if(newAppReview != null) service.Service_Start_Date__c = newAppReview.Final_Approval_Effective_Date__c; service.Approval_Expiration_Date__c = comReview.Final_Approval_End_Date__c; service.Next_Expected_Review_Type__c = comReview.Next_Expected_Review_Type_If_Any__c ; system.debug('TRE-> '+comReview.Next_Expected_Review_Type__c); System.debug('DRT->'+comReview.Final_Approval_End_Date__c); System.debug('DRT->'+service.Approval_Expiration_Date__c); if(comReview.status__c == 'Denied') service.Service_Termination_Date__c = comReview.Final_Approval_Effective_Date__c; else if(comReview.Next_Expected_Review_Type_If_Any__c == 'N/A') service.Service_Termination_Date__c = comReview.Final_Approval_End_Date__c; //else service.Service_Termination_Date__c = comReview.Final_Approval_End_Date__c; service.Approval_Expiration_Countdown__c = comReview.Approval_Expiration_Countdown__c; if(comReview.Related_Insurance_Review__c != null) service.Policy_Approved__c = comReview.Related_Insurance_Review__r.Policy_Requesting_Approval__c; } update services; List Services2 = [SELECT id, StageName FROM Opportunity WHERE id IN :oppsIds2]; for(Opportunity Service : Services2){ Service.StageName = 'Pending committee decision'; } update services2; }