You need to sign in to do that
Don't have an account?
SOQL Join
Hi all this is doing my head in all i have is a query:
Select p.PO_Ref__c, (Select id, CreatedDate, Effort__c, Billed__c,Submitted_Date__c From Time_Sheets__r) From Project_Activity__c p
now i want to loop through each project activity and pull out the time sheet so ive written:
for(Project_Activity__c p : ProjectActivityList)
{
for(Time_Sheet__c t : p.Time_Sheets__r)
{
TimeSheetList.add(t);
}
}
Am i doing something stupid here? i thought that work work fine but its complaining that im trying to de-reference a null object.
Does anyone have any ideas?
Thanks
Basically your code appears to be OK, but what is TimeSheetList, and how have you declared it? You should have a line like
List<Time_Sheets__c> TimeSheetList = new List<Time_Sheets__c>();
prior to calling this loop.
All Answers
Hi,
You are trying to refer object or object list without initialzing. get help from following links.
http://boards.developerforce.com/t5/Apex-Code-Development/Attempt-to-de-reference-a-null-object-Cant-figure-out-why-I-am/m-p/328099#M58155
http://boards.developerforce.com/t5/Visualforce-Development/System-NullPointerException/m-p/327541#M40090
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
chamil's blog
Basically your code appears to be OK, but what is TimeSheetList, and how have you declared it? You should have a line like
List<Time_Sheets__c> TimeSheetList = new List<Time_Sheets__c>();
prior to calling this loop.
And I presume too that you're populating ProjectActivityList before getting into this loop:
List<Project_Activity__c> ProjectActivityList = [Select p.PO_Ref__c, (Select id, CreatedDate, Effort__c, Billed__c,Submitted_Date__c From Time_Sheets__r) From Project_Activity__c p];
Only Initialization doesn't work,
You would also need to check if the child record list is empty or not.
Thanks all, it turn out that the code was ok i'd just not declared the lists properly so i just added :
List<Time_Sheet__c> TimeSheetList = new List<Time_Sheet__c>();
List<Project_Activity__c> ProjectActivityList = new List<Project_Activity__c>();
and it now works. cheers all.