function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Angello Camacho DragoAngello Camacho Drago 

Map get blank value when I call get method

Hi every one, 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:
 
Map<Id, List<npe03__Recurring_Donation__c>> rdsMap = new Map<Id, List<npe03__Recurring_Donation__c>>();
  for(Id id : Ids){
    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){
        if(id == rd.npe03__Organization__c){
          rdOld.add(rd);
        }
      }
      else if(rd.npe03__Contact__c != null){
        if(id == rd.npe03__Contact__c){
          rdOld.add(rd);
        }
      }
    }
    if(rdOld.size()>0){
      rdsMap.put(id, rdOld);
    }
  }​
  for(npe03__Recurring_Donation__c rdNew : trigger.new){
       else 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);//here I get an empty list            
            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[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');
                }
          }
        } 
      }
}

 
Alain CabonAlain Cabon
Hi,
 
for(npe03__Recurring_Donation__c rdNew : trigger.new){
       else if(rdNew.npe03__Contact__c != null){
          if(rdsMap.containsKey(rdNew.npe03__Contact__c)){

It lacks some lines before the "else" (you have removed a comment or a system.debug probably with the "if" after the copy/paste )

Regards
Angello Camacho DragoAngello Camacho Drago
Hi Alain thanks for you reply, yes I remove some lines but I don't think these lines are needed, the problem is after the if where ask if the map conatains the key, because before the for I fill the map and I have an if where I ask if the list have items, but when I call the get method I only get ().