How can I get the sum of all the length of select Options document I only want the value of the Selected Documents.
docNames = new List<SelectOption>();
for (Document d : [
SELECT Id, Name , Body, BodyLength
FROM Document
WHERE (FolderId =: UserInfo.getUserId() OR FolderId =: '00lG0000001bBXb')
AND ContentType = 'application/pdf'
]){
docNames.add(
new SelectOption(d.Id,d.Name + ' - ' + String.valueof(d.BodyLength) + ' bytes')
);
for (Integer i=0 ; i<= docNames.size() ; i++){
docNames.BodyLength[i] ;
}
}
Then I want do a try and catch so I dont let the user submit PDF files that sums up more than 5MB
try {
if(d.BodyLength/1048576 >= 5) {
ApexPages.addmessage(new ApexPages.message(
ApexPages.severity.INFO,
'The size of the file you are trying to upload is more than 5 MB. Please select another file.')
);
System.debug(' size > 5mb');
}
}
catch(Exception pokemon){ // gotta catch em all!
System.debug('ERROR:' + e);
}
Exception
are you actually expecting? Are you having any problems with your code? You don't actually ask a question as is.try
/catch
? It seems completely irrelevant to what you are trying to accomplish. A good question will only contain what is relevant in addition to making the intention clear. You are also missing a lot of context. Is this on aVisualforce Page
? How are they being selected in the first place?body
in the query