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
RajaMohanRajaMohan 

Attempt to de-reference a null object

Hi

 

while I am uploading the data from dataloader I am getting the following error.

 

ContractPremiumUpdate: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.ContractPremiumUpdate: line 38, column 8

 

Code:

 

trigger ContractPremiumUpdate on Contract ( after update) {

Set<Id> accid = new Set<Id>();
// List<Account> listacc = new List<Account>();
    for (Contract c : Trigger.new) {
            accid.add(c.AccountId);
    }
//listacc.clear();

     Map<ID,Account> listacc = new Map<ID,Account>{}; //NOTE: NOW, WE ARE INSTANTIATING A MAP, INSTEAD OF A LIST
     Map<ID,Account> acc = new Map<ID, Account>([Select a.Id,a.Premiumaccount__c, a.Name From Account a where a.id IN :accid limit 1 ]);
   
// Account acc = [Select a.Premiumaccount__c, a.Name, a.Id From Account a where a.id IN :accid limit 1 ];
    for (Integer i=0;i<trigger.new.size();i++){
    if((trigger.new[i].Post_Deal_Qualit_t__c == 'Gold' ||
       trigger.new[i].Post_Deal_Qualit_t__c == 'Silber' ||
       trigger.new[i].Post_Deal_Qualit_t__c == 'Platin'))
      {
         Account tmpLead = acc.Get(trigger.new[i].AccountId);
       tmpLead.Premiumaccount__c = 'Premium Partner';
       listacc.put(tmpLead.id,tmpLead);
      }
       
    }

update listacc.values();
}

 

Kindly help me in this. This is very urgent.

 

Thanks

Raj

hisrinuhisrinu

I think below line is giving the problem

 

trigger ContractPremiumUpdate on Contract ( after update) {

Set<Id> accid = new Set<Id>();
// List<Account> listacc = new List<Account>();
    for (Contract c : Trigger.new) {
            accid.add(c.AccountId);
    }
//listacc.clear();

     Map<ID,Account> listacc = new Map<ID,Account>{}; //NOTE: NOW, WE ARE INSTANTIATING A MAP, INSTEAD OF A LIST
     Map<ID,Account> acc = new Map<ID, Account>([Select a.Id,a.Premiumaccount__c, a.Name From Account a where a.id IN :accid limit 1 ]);
   
// Account acc = [Select a.Premiumaccount__c, a.Name, a.Id From Account a where a.id IN :accid limit 1 ];
    for (Integer i=0;i<trigger.new.size();i++){
    if((trigger.new[i].Post_Deal_Qualit_t__c == 'Gold' ||
       trigger.new[i].Post_Deal_Qualit_t__c == 'Silber' ||
       trigger.new[i].Post_Deal_Qualit_t__c == 'Platin'))
      {
       if(acc.containsKey(trigger.new[i].AccountId)){

           Account tmpLead = acc.Get(trigger.new[i].AccountId);
           tmpLead.Premiumaccount__c = 'Premium Partner';
           listacc.put(tmpLead.id,tmpLead);

       }
      }
       
    }

update listacc.values();
}

 

Pradeep_NavatarPradeep_Navatar

It seems that the data for the required fields is missing and due to that error is showing up.