You need to sign in to do that
Don't have an account?
Douglas Traster
System.NullPointerException: Attempt to de-reference a null object error
I am getting the following error on a trigger I am trying to initiate.
System.NullPointerException: Attempt to de-reference a null object: Trigger.activeOpp: line 42, column 1
Help!!! I know it is a null value on one, but not sure where to change the code...
trigger activeOpp on Opportunity (after insert, after update) {
List<contact> conUpdList = new List <contact>();
List<Id> oppConIDList = new List<Id>();
List<opportunity> oppConList = new List<opportunity>();
List<Contact> conList = new List<Contact>();
Map<ID, Contact> conMap = new Map<ID, Contact>();
for (opportunity opp: Trigger.new){
if(opp.Contact__c!= null){
oppConList.add(opp);
oppConIDList.add(opp.Contact__c);
}
}
if(!oppConIDList.isEmpty()){
conList = [select Name__c, Active_Opportunity__c from contact where Name__c = :oppConIDList];
}
if(!conList.isEmpty()){
for(Contact con : conList){
conMap.put(con.ID,con);
}
}
if(!oppConList.isEmpty()){
for(Opportunity optyObj : oppConList){
Contact c = conMap.get(optyObj.Contact__c);
if (optyObj.StageName == 'Closed Won' || optyObj.StageName == 'Closed Lost'){
c.Active_Opportunity__c = False;
}
else if(optyObj.StageName == 'Prospecting'
|| optyObj.StageName == 'Qualified Interest'
|| optyObj.StageName == 'Needs Analysis'
|| optyObj.StageName == 'Value Proposition'
|| optyObj.StageName == 'Proposal/Price Quote'
|| optyObj.StageName == 'Negotiation/Review'
|| optyObj.StageName == 'Verbal Commit'
|| optyObj.StageName == 'Closed Pending'){
c.Active_Opportunity__c = True;
}
conUpdList.add(c);
}
}
if(!conUpdList.isEmpty()){
update conUpdList;
}
}
System.NullPointerException: Attempt to de-reference a null object: Trigger.activeOpp: line 42, column 1
Help!!! I know it is a null value on one, but not sure where to change the code...
trigger activeOpp on Opportunity (after insert, after update) {
List<contact> conUpdList = new List <contact>();
List<Id> oppConIDList = new List<Id>();
List<opportunity> oppConList = new List<opportunity>();
List<Contact> conList = new List<Contact>();
Map<ID, Contact> conMap = new Map<ID, Contact>();
for (opportunity opp: Trigger.new){
if(opp.Contact__c!= null){
oppConList.add(opp);
oppConIDList.add(opp.Contact__c);
}
}
if(!oppConIDList.isEmpty()){
conList = [select Name__c, Active_Opportunity__c from contact where Name__c = :oppConIDList];
}
if(!conList.isEmpty()){
for(Contact con : conList){
conMap.put(con.ID,con);
}
}
if(!oppConList.isEmpty()){
for(Opportunity optyObj : oppConList){
Contact c = conMap.get(optyObj.Contact__c);
if (optyObj.StageName == 'Closed Won' || optyObj.StageName == 'Closed Lost'){
c.Active_Opportunity__c = False;
}
else if(optyObj.StageName == 'Prospecting'
|| optyObj.StageName == 'Qualified Interest'
|| optyObj.StageName == 'Needs Analysis'
|| optyObj.StageName == 'Value Proposition'
|| optyObj.StageName == 'Proposal/Price Quote'
|| optyObj.StageName == 'Negotiation/Review'
|| optyObj.StageName == 'Verbal Commit'
|| optyObj.StageName == 'Closed Pending'){
c.Active_Opportunity__c = True;
}
conUpdList.add(c);
}
}
if(!conUpdList.isEmpty()){
update conUpdList;
}
}
All Answers
no i dont think so
since you have if and else if not if and else block ther is possiblity your record may not enter neither if nor else if . If you put some system.debug statments from line 27 onwards and set a debug log you will be able to find exact execution path.
hope this helps