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
davecrusodavecruso 

File attachment - Upload works; how to delete?

Hi all, 

 

After some poking and prodding, I've gotten file attachments to work. Files are associated with apprenticeships; here's the code that I'm using for the controller extension

 

 

public PageReference deletefile() {

PageReference pageRef = System.currentPageReference();

apprenticeshipId = pageRef.getParameters().get('id');

ctContactId = pageRef.getParameters().get('ctContactId');

url = '/apex/CTN_Apprenticeship';

 

fileId = System.currentPageReference().getParameters().get('fileId');

attachment = [select Apprenticeship__c.attachment__r.id from Apprenticeship__c where attachment__r.id = 'fileId'];

delete attachment;

 

urlstring = url + '?id=' + apprenticeshipId + '&ctContactId=' + ctContactId;

PageReference ref = new PageReference(urlstring); ref.setRedirect(true); return ref;

}

 

 

 

 

The question is about how users can remove files. How do I query the NotesAndAttachments child object? I've tried a bunch of things, but all seem to throw errors (and googling "NotesAndAttachments" only pulls up minimal results!).

 

Has anyone been through this? Does anyone have suggestions about what a simple query might look like that I could use to populate a deletefile() action, or point me toward a code snippet that might accomplish the same? Thanks so much!

 

--Dave 

 

 

Message Edited by davecruso on 06-03-2009 08:56 AM
Message Edited by davecruso on 06-03-2009 08:57 AM
Message Edited by davecruso on 06-03-2009 08:58 AM
Ezio_2010Ezio_2010

Man, im in the same, as in many sforce stuff... got few ideas to do it, but i think there must be a best approach

 

anyway...if u find something lemme know

 

cya

Ezio_2010Ezio_2010
Man, it wasn't my intention to post a solution, I'm stuck in the same thing...but somehow I messed with this and post a solution, if u can, open it again or delete my last post.
bblaybblay

Maybe this gives some ideas. Mine is a custom object Member__c that stores image attachments. Each person can upload multiple pictures but only one of their images is displayed in the search. 

 

 

This is the query I have to display a search that shows each member's image: 

 

 

Public PageReference query() {
ccts = [SELECT createdDate, Name, (Select id From Member__c.Attachments)
 FROM Member__c 
 ORDER BY createdDate DESC limit 100 ] ;
 return null;
 }

 

Shows the search for the first image only:

 

<apex:repeat value="{!Member__c.attachments}" var="attachment" rows="1" first="0">
   <img style="border: 1px black solid;" src="{!URLFOR($Action.Attachment.Download, attachment.Id)}" alt="" 	   width="100" height="100" id="img1"/>
</apex:repeat>

 

 

If you were able to figure out how to delete these attachments though would you be able to show me what you've done? I know your post is from a year ago!

 

Thanks!

paul-lmipaul-lmi

Attachments are accessed like any other standard SObject.  The schema is "Attachment" not "NotesAndAttachments".

 

So to delete all the Attachments on a row of your custom object:

 

Member__c m = [query to get your custom object (must have the ID to use delete)];

List<Attachment> a -= [select id from attachment where parentid = :m.id];

 

if(a.size() > 0){

   delete a;

}

SalmanSalman
Hii davecruso,

Can you please check this application for Attachments,

MassMailer DOCS let’s you easily mass email email attachments to your leads or contacts while securely storing your files with Rackspace Cloud Files.

You can try this app by installing from appexchange  -Massmailer Docs

You can learn more details about the product on this website - Link