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
PNSPNS 

Listing attachments

Hi folks...

 

I am trying to get a list of the file attachments associated with an account that I have created in Salesforce.com, but cannot figure out the details. (The attachments are simple text files that have been uploaded via the website and are fully accessible in the corresponding account via any browser.)

 

Using Java and the Web Services API, my code looks like this (listing the essential bits only):

 

SObject[] records = null;

try
{
	records = binding.query("SELECT Id, Name FROM Account").getRecords();
			
	if (records != null)
	{
		System.out.println("Found " + records.length + " records");
	}

	Account account = null;
	QueryResult attachments = null;
					
	for (int i = 0; i < records.length; i++)
	{
		account = (Account)records[i];
		System.out.println(account.getId() + ": " + account.getName());
				
		attachments = account.getAttachments();
				
		System.out.println("Attempt 1: attachments = " + attachments);

		attachments = account.getNotesAndAttachments();
				
		System.out.println("Attempt 2: attachments = " + attachments);
				
		attachments = binding.query("SELECT Id, Name FROM Attachment WHERE ParentId = '" + account.getId() + "'");
		System.out.println("Attempt 3: attachments = " + attachments);
	}				
}
catch (Exception e)
{
}

 

The first query does return several account objects, including the one that holds the attached files (all ending in .txt). However, no attachments are retrieved from any of these account objects.

 

As you can see, I try to get the attachments in 3 different ways, i.e. via calling the getAttachments(), getNotesAndAttachments() and query() methods. The first two always return null, whereas the last returns 0 records found.

 

Obviously I am missing something, so could anyone please enlighten me?

 

Thanks!

PNSPNS

I also tried the Schema Explorer in the Force.com IDE and it does not show any attachments, either.

 

Weird... The files are there, listed in the web page of the corresponding account under "Notes & Attachments" of type "Feed Attachment", or under the category Files in a search. Running queries against other standard objects (e.g., AccountFeed or NoteAndAttachment) does not help, either.

 

How on earth does one access these files/attachments/feeds/whatever?

 

PNSPNS

Hmm... The files I was trying to retrieve are not plain attachments but "Feed Attachments", uploaded via Chatter > Attach File, thus they should be retrieved via a FeedPost object. So, by running a SOQL query like

 

 

SELECT Id, Type, FeedPost.ID, FeedPost.Title, FeedPost.ContentFileName, FeedPost.Body, FeedPost.IsDeleted FROM AccountFeed

 solves the problem.

 

The Attachment and NoteAndAttachment objects are populated via Notes and Attachments > Attach File, not via Chatter > Attach File, and are listed there as "Attachment" (not Feed Attachment).

 

I am still puzzled as to how the IsDeleted field works, because it remains false even for documents that I have deleted (whereas the corresponding ContentFileName gets a null value for such objects). Anyway, I guess I will discover it along the way.

 

Hope the above helps someone save some time when doing a similar thing. 

 

I still don't get how