-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestUpload
More file actions
46 lines (35 loc) · 1.41 KB
/
testUpload
File metadata and controls
46 lines (35 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public class testUpload{
public Expense__c exp {get; set;}
public testUpload(){
exp = [select id, Name, Company__c, Expense_Type__c, Date__c, Total_Amount__c from Expense__c where id =: ApexPages.currentPage().getParameters().get('Id')];
}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = exp.id; // the record the file is attached to
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
public List<Attachment> getAttList(){
List<Attachment> aList = new List<Attachment>();
for(Attachment a: [select id, Name, Body, Description, ParentID, CreatedDate from Attachment where ParentID =: exp.Id ORDER BY CreatedDate DESC]){
aList.add(a);
}
return aList;
}
}