function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dedkinsdedkins 

Listing Attachments from both Account and Tasks

I'm trying to separate attachments from the standard notes and attachments list for an account (we use person accounts) and having a heck of a time.  I've tried a number of different ways to get to the information.  I can successfully pull a list of attachments from the account record if the attachment was directly attached.  But I cannot seem to get to attachments that are in tasks in the account record.  

 

I have a record I'm using for test that has one attachment directly attached and another in a task.

 

Error when I use the following code is "Attempting to reference a null object":

"

Task t;

public List<Task> getTasks(){
List<Task> t = [select id from Task where accountId = :ApexPages.currentPage().getParameters().get('id')];
return t;
}

public List<Attachment> getTaskAttachments(){
List<Attachment> attach = [select Id,name from Attachment where parentId = :t.Id];
return attach;
}

"

Seems to me that the second method cannot see the list from the t variable.  If I change it from t:Id to :account.Id, I at least get the attachment directly attached to the account record.

 

When I try the following code is gives the error in Force IDE of Initial Term of field expression must be a concrete SObject List<Task>:

"

public List<Task> t = [select id from Task where accountId = :ApexPages.currentPage().getParameters().get('id')];

public List<Attachment> getTaskAttachments(){
List<Attachment> attach = [select Id,name from Attachment where parentId = :t.Id];
return attach;
}"

 

It will be apparent to many of you that I really don't know what I'm doing - with that said - I do appreciate any help you can provide.

 

Thank you.

Naidu PothiniNaidu Pothini
public List<Task> t = [select id from Task where accountId = :ApexPages.currentPage().getParameters().get('id')];

public List<Attachment> getTaskAttachments()
{
    List<Attachment> attach = [SELECT Id, Name FROM Attachment WHERE parentId IN :t];   
    return attach;
}

 Try this and let me know if it doesnt work