Advertisement
itdcole

VFZip Class

Sep 5th, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /*
  2. * AUTHOR : Avi ([email protected])
  3. * Modified by: D.Cole 2016/09/02
  4. * Changes: Line 17-19; search and replace characters not readable by component.
  5. * DESCRIPTION : Please note this is a early release of this component I will be updating this component and will completing the same with proper test classes
  6. *
  7. **/
  8. public class VFZip_Con_V2 {
  9. public Integer randomInt{get;set;}
  10.  
  11. public VFZip_Con_V2(){
  12. randomInt = getRandomNumber(10000);
  13. }
  14.  
  15. @RemoteAction
  16. public static List<AttachmentWrapper> getAttachments(String attachmentIdCSV){
  17. attachmentIdCSV = attachmentIdCSV.replace('[','');
  18. attachmentIdCSV = attachmentIdCSV.replace(']','');
  19. attachmentIdCSV = attachmentIdCSV.replace(' ','');
  20. List<String> attachmentIds = attachmentIdCSV.split(',');
  21.  
  22. return wrapAttachments([SELECT Id,Name,Body FROM Attachment WHERE Id IN:attachmentIds]);
  23. }
  24.  
  25.  
  26. private static List<AttachmentWrapper> wrapAttachments(List<Attachment> attachments){
  27. List<AttachmentWrapper> wrappers = new List<AttachmentWrapper>();
  28. for(Attachment att : attachments){
  29. wrappers.add(new AttachmentWrapper(att));
  30. }
  31.  
  32. return wrappers;
  33. }
  34.  
  35. public class AttachmentWrapper{
  36. public Attachment AttachmentObj;
  37. public String base64Body;
  38.  
  39. public AttachmentWrapper(Attachment AttachmentObj){
  40. this.AttachmentObj = AttachmentObj;
  41. this.base64Body = EncodingUtil.base64Encode(AttachmentObj.Body);
  42. this.AttachmentObj.Body = NULL;
  43. }
  44. }
  45.  
  46. /*
  47. *Random number generator to change the js function name if multiple components us
  48. ***/
  49. private Integer getRandomNumber(Integer size){
  50. Double d = Math.random() * size;
  51. return d.intValue();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement