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? Jul 25, 2016 at 11:06
  • delete this events and after few operations reinsert them again 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. Jun 12 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.