• heinleinandy
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi,
I have spent a year in college on C++, and understand computer programming fairly well.
With that said, this is my first attempt and apex, triggers and SOQL (or SQL for that matter) and i could use some help.
 
Here is my apex class
 
public class calculateResources {
    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;
   
    }
}
 
 
and here is my trigger
 

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

Any help would be great, i am not real sure where the null pointer is that im attempting to dereference
Thanks


Message Edited by heinleinandy on 07-07-2008 07:04 AM

Message Edited by heinleinandy on 07-07-2008 07:05 AM
Hey all,
The part of the project that I am working on has basically three levels of custom objects. The design looks something like this:
 
Top Level object
   |
 / | \
Middle Level Object
    |
  / | \
Lower Level Object
 
the lowest level has a number field (hours) that will be input from user. The field in middle level needs to be a sum of all hours in the lower level. Likewise, the Top level will need a sum of all the middle level hours.
 
I am looking at roll up summariesas a way to acomplish this, but i can not have the top level be the master detail for the middle and also have the middle be a master detail of lower level.
 
Is there some way to accomplish this?
Thanks in advance
Hey all,
The part of the project that I am working on has basically three levels of custom objects. The design looks something like this:
 
Top Level object
   |
 / | \
Middle Level Object
    |
  / | \
Lower Level Object
 
the lowest level has a number field (hours) that will be input from user. The field in middle level needs to be a sum of all hours in the lower level. Likewise, the Top level will need a sum of all the middle level hours.
 
I am looking at roll up summariesas a way to acomplish this, but i can not have the top level be the master detail for the middle and also have the middle be a master detail of lower level.
 
Is there some way to accomplish this?
Thanks in advance