You need to sign in to do that
Don't have an account?
Simple error on a simple trigger
public static void addResource(PersonalProject__c PP){
MonthlyProject__c MP = [SELECT Hours_This_Term__c, WholeProject__c FROM MonthlyProject__c WHERE id= : PP.MonthlyProject__c];
MP.Hours_This_Term__c += PP.hours_spent__c;
WholeProject__c WP = [SELECT AllocatedHours__c FROM WholeProject__c WHERE id= :MP.WholeProject__c];
WP.AllocatedHours__c += PP.hours_spent__c;
}
trigger addResource on PersonalProject__c (after insert) {
for (Integer i = 0; i < Trigger.new.size(); i++)
calculateResources.addResource(Trigger.new[i]);
}
When I create a personal project, i need MonthlyProject__c.hours_this_term__c to update by adding personalProject__c.hours_spent__c. and similarly with whole project updating from MP.hours this term.
When i run this, i get
Apex trigger addResource caused an unexpected exception, contact your administrator: addResource: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.calculateResources.addResource: line 5, column 9
Message Edited by heinleinandy on 07-07-2008 07:04 AM
Message Edited by heinleinandy on 07-07-2008 07:05 AM
To fix it, either do an explicit test for null (if MP==null) or use a try block. You probably just want to ignore the PP's that are missing all the fields, so you could just log the error and then leave the routine.