You need to sign in to do that
Don't have an account?
Walter@Adicio
Question about getting datetime values out of of a map, only want ealiest date found
If you have multiple datetime values in a map is there a way to grab the earliest 'lowest value' date, when you get the values from the map?
Thank you.
Do you need a Map or a List for this?
Anyway, for Map, try this untested code:
Collection values = map.values();
Collections.sort(values);
String lowestValue = values.get(0);
Thanks and Regards,
Kerwin
All Answers
Do you need a Map or a List for this?
Anyway, for Map, try this untested code:
Collection values = map.values();
Collections.sort(values);
String lowestValue = values.get(0);
Thanks and Regards,
Kerwin
Thank you, I will look into your example it looks like what I want. I am trying to change a field in a case when the case loads or is viewed but I am having trouble with that. I have a trigger changing the field when the case is edited, and I had written something like this. Any advice is much appriciated if I am not doing this efficiently.
public class caseChange {
public static void makeChange(Case[] cs){
Set<Id> caseIds = new Set<Id>();
Set<Id> internalUserIds = new Set<Id>();
Map<Id,Datetime> commentCommunicationToCaseMap = new Map<Id,Datetime>();
Map<Id,Datetime> emailCommunicationToCaseMap = new Map<Id,Datetime>();
for(Case c : cs)
{caseIds.add(c.Id);}
for(User u : [Select Id,UserType from User where UserType='Standard'])
{internalUserIds.add(u.Id);}
for(CaseComment cc : [Select IsPublished, CreatedDate, CreatedById,ParentId,CreatedBy.Username From CaseComment
where CreatedById In :internalUserIds and
ParentId in : caseIds and
IsPublished=true and
CreatedBy.Username <> 'systemuser@mydomain.com'
ORDER BY CreatedDate limit 1])
{commentCommunicationToCaseMap.put(cc.ParentId,cc.CreatedDate);}
for(EmailMessage e : [select Incoming, CreatedDate, CreatedById,ParentId,CreatedBy.Username From EmailMessage
where Incoming=false and
ParentId In :caseIds and
CreatedById In :internalUserIds and
CreatedBy.Username <> 'systemuser@mydomain.com'
ORDER BY CreatedDate limit 1])
{emailCommunicationToCaseMap.put(e.ParentId,e.CreatedDate);}
for(Case c : cs){
if(c.First_Public_Response__c==null&&commentCommunicationToCaseMap.get(c.Id)<emailCommunicationToCaseMap.get(c.Id)) {c.First_Public_Response__c = commentCommunicationToCaseMap.get(c.Id);}
else if (c.First_Public_Response__c==null&&commentCommunicationToCaseMap.get(c.Id)>emailCommunicationToCaseMap.get(c.Id))
{c.First_Public_Response__c = emailCommunicationToCaseMap.get(c.Id);}
}
}
For trying to make the case field change on case view I have overridden the case view in case buttons and links setup to a VF page. I've tried using the standard controller, Case with apex page extension and page action to a page reference and tried calling to something similar to above in the page reference.