You need to sign in to do that
Don't have an account?

Update Attachment without 'Re-Attaching' it once done.
Is there a way to have them able to update an attachment file and have it update the attached file without having to re-attach a new version and deleting the old one?
Find below the sample code :
try
{
List<Attachment> lstDoc = Database.query('SELECT d.parentid, d.Name, d.Body FROM Attachment d ); // you can use your own filter criteria..
if(lstDoc != null && lstDoc.size() > 0)
{
lstDoc[0].body = filebody;
lstDoc[0].name = filename;
lstDoc[0].parentid = parentid;
update lstDoc[0];
}
else
{
transient Attachment a = new Attachment();
a.body = filebody;
a.name = filename;
a.parentid = parentid;
insert a;
}
}
catch(Exception e)
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,e.getmessage());
ApexPages.addMessage(myMsg);
}
Hope this helps