I have a trigger that when I insert data into a custom object create a map with the id of a contact as a key and a list of the custom object as the value, when I check if the key is contained in the map I get true, but when I try to get the value I get (), but when I filled the map I check if the list has items with an if list.size()>0, this is my code:
for(Id id : Ids){
Boolean accs = false;
Boolean cs = false;
List<npe03__Recurring_Donation__c> rdOld = new List<npe03__Recurring_Donation__c>();
for(npe03__Recurring_Donation__c rd : rds){
if(rd.npe03__Organization__c != null && !cs){
if(id == rd.npe03__Organization__c){
rdOld.add(rd);
accs = true;
}
}
else if(rd.npe03__Contact__c != null && !accs){
if(id == rd.npe03__Contact__c){
rdOld.add(rd);
cs = true;
}
}
}
if(rdOld.size()>0){
rdsMap.put(id, rdOld);
accs = false;
cs = false;
}
}
for(npe03__Recurring_Donation__c rdNew : trigger.new){
if(rdNew.Tipo_de_Compromiso__c == 'Nuevo por Aumento'){
if(rdNew.npe03__Contact__c != null){
if(rdsMap.containsKey(rdNew.npe03__Contact__c)){
List<npe03__Recurring_Donation__c> rdsSort = new List<npe03__Recurring_Donation__c>();
List<npe03__Recurring_Donation__c> rdsOld = rdsMap.get(rdNew.npe03__Contact__c).clone();
integer targetsize = rdsOld.size();
while(rdsSort.size() != targetsize){
datetime dt = Datetime.newInstance(1900, 1, 1, 00, 00, 00);
integer i = 0;
integer mini = 0;
for(i = 0; i != rdsOld.size(); i ++){
if(rdsOld[i].CreatedDate > dt){
dt = rdsOld[i].CreatedDate;
mini = i;
}
}
rdsSort.add(rdsOld[mini]);
rdsOld.remove(mini);
}
if(rdsSort.size()>0 && rdsSort[0].npe03__Amount__c < rdNew.npe03__Amount__c){
}
else{
rdNew.addError('No puede crear un Compromiso de Donación con el Tipo de Compormiso "Nuevo por Aumento", porque el monto ingresado es menor o igual que el monto del Compromiso de Donación Anterior');
}
}
}
}
else if