+ Start a Discussion
ruchika Nayyarruchika Nayyar 

Error: Invalid Data. 

  Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger myruchika.contact caused an unexpected exception, contact your administrator: myruchika.contact: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Class.myruchika.contact1.Managefeeonupdate: line 48, column 1



public void onafterupdate(list<contact>Triggernew,list<contact>Triggerold,map<ID,contact>Triggernewmap,map<ID,contact>Triggeroldmap)
{
  Managefeeonupdate(TriggerNew,Triggeroldmap);
}
void Managefeeonupdate(list<contact>Triggernew,Map<ID,contact>Triggeroldmap)
{
    set<ID> setAccID= New set<ID>();
    list<Account> lstAcc=New list<Account>();
    for(contact objC: TriggerNew)
    {
        if (objC.AccountId!=null && objC.myruchika__fee__c!=TriggeroldMap.get(objC.AccountID).myruchika__fee__c)
           {
           setAccID.Add(objC.AccountId);
           }
    }         
     if(setAccID.size()>0)
           {
               for(Account objA:[select ID,myruchika__totalfees__c,(select ID,myruchika__fee__c From contacts Where myruchika__fee__c!=null) From Account Where ID in :setAccID])
               {
                   
               
           Decimal amt=0;
           for(contact objC:objA.contacts)
           {
               amt += objC.myruchika__fee__c;
           }
         objA.myruchika__totalfees__c=amt;
               
           lstAcc.add(objA);
           }
           If(lstAcc.size()>0)
           {
               update lstAcc;
               
           }
}
Bhanu MaheshBhanu Mahesh
Hi Ruchika,

The error is because you are trying to pass the account Id for TriggeroldMap. But this map has the contact records as the trigger is on contact object. So you have to pass contact id to get the value for that Id. It will return null if we pass Account Id as key

The below line 
if (objC.AccountId!=null && objC.myruchika__fee__c!=TriggeroldMap.get(objC.AccountID).myruchika__fee__c)
try replace it with below code
 
if (objC.AccountId!=null && objC.myruchika__fee__c!=TriggeroldMap.get(objC.Id).myruchika__fee__c)

Mark this as "SOLVED" if this answer resolves your issue.

Thansk & Regards,
Bhanu Mahesh Gadi