+ Start a Discussion
Ronaldo CostaRonaldo Costa 

future trigger - unhandled exception

Hello all,
I'm working on a roll-up summary trigger to rollup values separated by commas. and I'm getting the following error:

Apex script unhandled exception by user/organization: 005300000073SRQ/00D5400000097yi
Source organization: 00D30000001HvZp (null)
Failed to invoke future method 'public static void ProcessConcessionsAsync(Set<Id>)' on class 'ConcessionsRollUpTriggerHandler' for job id '7075400000IMKrB'

caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Concessions__c.Name

Class.ConcessionsRollUpTriggerHandler.ProcessConcessionsAsync: line 20, column 1


Class:
//class//class
  public with sharing class ConcessionsRollUpTriggerHandler {

    @future 
    public static void ProcessConcessionsAsync(Set<ID> agreementIds){

      // holds o mapa de agreements id separando as concessoes por ,
      Map<Id, String> agreementConcessionMap = new Map<Id, String>();

      // get ALL of the concessions for all affected agreement to build
      List<Concessions__c> agreementConcessions = [select id, Agreement__c from Concessions__c 
        where Agreement__c IN :agreementIds order by Concessions__c.name]; //stopped here

      for (Concessions__c ar : agreementConcessions) {
        //if (!agreementConcessionMap.containsKey(ar.Agreement__c)) {
          // if the key (agreement) doesn't exist, add it with concession name
          //agreementConcessionMap.put(ar.Agreement__c,ar.Name);
        //} else {
          // if the key (agreement) already exist, add ", concession-name"
          agreementConcessionMap.put(ar.Agreement__c,agreementConcessionMap.get(ar.Agreement__c) + ', ' + ar.Name);
        //}
      }

      // get the agreements that were affected
      List<Apttus__APTS_Agreement__c> agreements = [select id from Apttus__APTS_Agreement__c where Id IN :agreementIds];

      // add the comma separated list of concessions
      for (Apttus__APTS_Agreement__c a : agreements)
        a.Concessions_Holder_Test__c  = agreementConcessionMap.get(a.id);

      // update the agreements
      update agreements;

    }  

  }
Trigger
trigger ConcessionsRollUpTrigger on Concessions__c (after delete, after insert, after update) {

  // shot dps do insert e update
  if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter){

    // search os ids de tds agreements afetados
    Set<Id> agreementIds = new Set<Id>();
    for (Concessions__c ar : [select Id, Agreement__c from Concessions__c 
      where Id IN :Trigger.newMap.keySet()])
      agreementIds.add(ar.Agreement__c);

    // processa os agreements
    ConcessionsRollUpTriggerHandler.ProcessConcessionsAsync(agreementIds);

  // shot qdo os registros são deletados
  } else if(Trigger.isDelete && Trigger.isAfter){

    // search os ids de tds agreements afetados
    Set<Id> agreementIds = new Set<Id>();
    for (ID id : Trigger.oldMap.keySet())
      agreementIds.add(Trigger.oldMap.get(id).Agreement__c);
//
    // process the agreements
    ConcessionsRollUpTriggerHandler.ProcessConcessionsAsync(agreementIds);

  }

}

Any ideas?

Thanks,
Ron

 
kirubakaran viswanathankirubakaran viswanathan
The Name field was missed to query causing this problem
Please change the query like
List<Concessions__c> agreementConcessions = [select id, name, Agreement__c from Concessions__c where Agreement__c IN :agreementIds order by name];