+ Start a Discussion
TheLearnerTheLearner 

Very urgent------Throwing an error while saving the record

 
 Hi Experts,
 
 while saving the record in the child that ie triio sub application its throwing in an error ,
 
 "Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger tRIIO_Update_Project_from_SubApplication caused an unexpected exception, contact your administrator: tRIIO_Update_Project_from_SubApplication: execution of AfterInsert caused by: System.SObjectException: Invalid field PrjApplInvoiceSubDateMap for AggregateResult: Trigger.tRIIO_Update_Project_from_SubApplication: line 47, column 1".

Could anyone help me please
 
 trigger tRIIO_Update_Project_from_SubApplication on tRIIO_Sub_Application__c (after insert,after update,after delete) {

List<AggregateResult> ProjectAppNameResult=new List<AggregateResult>();
Map<String,Date> PrjApplAssRejDateMap=new Map<String,Date>() ;
Map<String,Date> PrjApplInvoiceSubDateMap=new Map<String,Date>() ;
List<String> applicationNameLst=new List<String>();
List<tRIIO_Application__c> applicationLst=new List<tRIIO_Application__c>();
Map<String,tRIIO_Application__c> applicationMap=new Map<String,tRIIO_Application__c>();
List<triio_project__c> PrjLst=new List<triio_project__c>();
set<Id> projectIds = new set<Id>();
List<tRIIO_Sub_Application__c> subAppRecrds=new List<tRIIO_Sub_Application__c>();

 for(tRIIO_Sub_Application__c subapp : (trigger.isdelete?trigger.old:trigger.new))
    {
     if(subapp.Project_Name__c!=null)
     {
            projectIds.add(subapp.Project_Name__c);
            subAppRecrds.add(subapp);
      }
    }
 
 
ProjectAppNameResult = [SELECT  Project_Name__c,
                        Max(h_Dt_Assessed_Rejected__c) MaxAppDateAssedRejected,
                        Max(h_Application_Invoice_SubDate__c) MaxAppInvoiceSubDate FROM tRIIO_Sub_Application__c
                        where Project_Name__c !=null group by Project_Name__c ];        
System.debug('@@ProjectAppNameResult -'+ProjectAppNameResult);
 
for(AggregateResult prjAppName: ProjectAppNameResult)
{
    PrjApplAssRejDateMap.put((String)prjAppName.get('Project_Name__c'),(Date)prjAppName.get('MaxAppDateAssedRejected'));
    PrjApplInvoiceSubDateMap.put((String)prjAppName.get('Project_Name__c'),(Date)prjAppName.get('PrjApplInvoiceSubDateMap'));
}
 
system.debug('@@PrjApplAssRejDateMap-'+PrjApplAssRejDateMap);
system.debug('@@PrjApplInvoiceSubDateMap-'+PrjApplInvoiceSubDateMap);
 
for(Id itrPrj: projectIds)
{
system.debug('@@itrPrj-'+itrPrj);
if(PrjApplAssRejDateMap.containskey('itrPrj') && PrjApplInvoiceSubDateMap.containskey('itrPrj'))
PrjLst.add(new tRIIO_Project__c(id=itrPrj,
                                 Invoice_Submitted_Date__c=PrjApplAssRejDateMap.get(itrPrj),
                                 Assessed_Approved_Date__c=PrjApplInvoiceSubDateMap.get(itrPrj)
                                ));
else if(PrjApplAssRejDateMap.containskey('itrPrj') && !PrjApplInvoiceSubDateMap.containskey('itrPrj'))
PrjLst.add(new tRIIO_Project__c(id=itrPrj,
                                 Invoice_Submitted_Date__c=PrjApplAssRejDateMap.get(itrPrj),
                                 Assessed_Approved_Date__c=null
                                ));
    
 else if(!PrjApplAssRejDateMap.containskey('itrPrj') && PrjApplInvoiceSubDateMap.containskey('itrPrj'))
PrjLst.add(new tRIIO_Project__c(id=itrPrj,
                                 Invoice_Submitted_Date__c=null,
                                 Assessed_Approved_Date__c=PrjApplInvoiceSubDateMap.get(itrPrj)
                                ));  
    
                            
}
 
if(!PrjLst.isEmpty())
  Update PrjLst;
 
 
  }
atla satheeshkumaratla satheeshkumar
Hi,

please give me the exatc line of code.I hope you are adding the aggregate Result to Map so that you are getting error.