Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. public Boolean Save() {
  2. Boolean saveStatus;
  3. List<ContentVersion> CVs = new List<ContentVersion>();
  4. List<ContentDocumentLink> CDLs = new List<ContentDocumentLink>();
  5. //Get the ContentVersion RecordTypeID for General FIles
  6. string CVRTID = [select id, name from recordtype where sObjectType = 'ContentVersion' and Name = 'Standard'].Id;
  7. for (ExtendedDocument doc : docs) {
  8. system.debug('Im in for look of docs');
  9. if (doc.file != null) {
  10. system.debug('Im in so doc.file is not null');
  11. ContentVersion v = new ContentVersion();
  12. v.RecordTypeId = CVRTID;
  13. v.versionData = doc.file;
  14. v.Description = doc.odContentVersion.Description;
  15. v.Document_Type__c = doc.odContentVersion.document_type__c;
  16. v.title = doc.fileName;
  17. v.pathOnClient =doc.fileName;
  18. //add convtentversion to list
  19. CVs.add(v);
  20. file=null;
  21. }
  22. //end of for loop below
  23. }
  24.  
  25. if(CVs.size() >=1) {
  26. for(ContentVersion CVSlist : CVs){
  27. try{
  28. insert CVSList;
  29. for (id opid : oppIds) {
  30.  
  31. //create the contentdcumentlink to link the contentversion to each of the opportunities
  32. CVSList = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :CVSList.Id];
  33.  
  34. ContentDocumentLink cdl =
  35. new ContentDocumentLink(
  36. ContentDocumentId=CVSList.ContentDocumentId,
  37. ShareType = 'V',
  38. LinkedEntityId=opid);
  39. //CDLs.add(cdl);
  40. insert cdl;
  41. }
  42. saveStatus = true;
  43. }
  44. catch (DMLException e) {
  45. system.debug('I thre an error while uploading the file.. missing data maybe');
  46. //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
  47. ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,
  48. 'Error uploading file');
  49. ApexPages.AddMessage(msg);
  50. saveStatus = false;
  51. }
  52. }
  53. }
  54. else{
  55. system.debug('I threw an error no file');
  56. ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.ERROR,
  57. 'You did not choose a file to upload. Please choose a file or Cancel');
  58. ApexPages.addMessage(msg);
  59. saveStatus = false;
  60. }
  61. return saveStatus;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement