You need to sign in to do that
Don't have an account?
Naveen Kvp
how to avoid null ponter exception in following trigger?
trigger updatepicklistlist on Orderc__c (after insert,after Update,after delete) {
Map<id,Account> mapAcc=new Map<id,Account>();
set<id> accids=new set<id>();
list<Orderc__c> lstorder=new list<Orderc__c>();
for(Orderc__c ord:trigger.new){
accids.add(ord.Party_Name__c);
}
for(Orderc__c ord:trigger.old){
accids.add(ord.Party_Name__c);
}
for(account acc:[select id,Status__c,Discount__c from account where id =: accids])
{
mapAcc.put(acc.id,acc);
System.debug('List of Acccounts@@@@@@@@@@@@@@@@@@'+mapAcc);
}
if(accids.Size()>0)
{
for(Orderc__c o:Trigger.New)
{
if(mapAcc.get(o.Party_Name__c) .Discount__c==Null)
{
o.addError('Please Enter Discount in Account');
}
else
{
mapAcc.get(o.Party_Name__c) .Status__C='Existing';
}
}
}
Update mapAcc.values();
}
Map<id,Account> mapAcc=new Map<id,Account>();
set<id> accids=new set<id>();
list<Orderc__c> lstorder=new list<Orderc__c>();
for(Orderc__c ord:trigger.new){
accids.add(ord.Party_Name__c);
}
for(Orderc__c ord:trigger.old){
accids.add(ord.Party_Name__c);
}
for(account acc:[select id,Status__c,Discount__c from account where id =: accids])
{
mapAcc.put(acc.id,acc);
System.debug('List of Acccounts@@@@@@@@@@@@@@@@@@'+mapAcc);
}
if(accids.Size()>0)
{
for(Orderc__c o:Trigger.New)
{
if(mapAcc.get(o.Party_Name__c) .Discount__c==Null)
{
o.addError('Please Enter Discount in Account');
}
else
{
mapAcc.get(o.Party_Name__c) .Status__C='Existing';
}
}
}
Update mapAcc.values();
}
if(mapAcc.get(o.Party_Name__c) != null)
before this condition: if(mapAcc.get(o.Party_Name__c) .Discount__c==Null)
This would be causing this error.
Replace your code with the code below
If that helps you, please mark this as best answer
Below is the updated code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal