2

I have a Map with Date Like Key and all Event on that day as a List of values. Here the code I use to create the map:

Map<Date,List<Event>> mappaeventidate= new Map<Date,List<Event>>(); 
    for(Event e:eventi_tutti){
        if(!mappaeventidate.containsKey(e.StartDateTime.date())){
            mappaeventidate.put(e.StartDateTime.date(),new List<Event>{e});
        }else{
            mappaeventidate.get(e.StartDateTime.date()).add(e);
        }           
    }

Now I need to clone the map, and after to delete the map I created before. I'm trying to use deepclone but I have a error. Here my code:

Map<Date,List<Event>> mappaeventidate2 =mappaeventidate.deepClone();

and the error when I save the trigger:

Operation only applies to SObject value map types: Map<Date,List<Event>>

I need to delete the List of Events inside the Map but before I want to store them in another Map. Is it possible?

2
  • Do you need to delete the events, or just clear the map? Commented Jul 25, 2016 at 11:06
  • delete this events and after few operations reinsert them again Commented Jul 25, 2016 at 11:11

1 Answer 1

3

I solve the problem with this code.

Map<Date,List<Event>> mappaeventtwo= new Map<Date,List<Event>>(); 
    for(Date d:mappaeventidate.keySet()){
        mappaeventtwo.put(d, mappaeventidate.get(d).deepClone());
    }

if anyone needs it

1
  • Thanks mate. This was really helpful. Commented Jun 12, 2022 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .