Guest User

Untitled

a guest
Nov 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. <apex:form id="frm">
  2. <font color="red"><apex:pageMessages ></apex:pageMessages></font>
  3. <apex:sectionHeader title="Attach File to Notes & Attachments"/>
  4. <apex:pageblock >
  5. <b> 1. Select the File</b><br/>
  6. Type the path of the file or click the Browse button to find the file.<br/>
  7. <br/><apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}"/> <!-- SENDS THE ATTACHED FILE INFO TO TESTMETHOD() -->
  8. <p></p>
  9. <b> 2. Click the "Attach File" button.</b><br/>
  10. ( When the upload is complete the file information will appear in Next Page )<br/>
  11.  
  12. <br/> <apex:actionRegion immediate="true" >
  13. <apex:commandbutton value="Attach File" action="{!showPopup}" id="saveButton" rerender="popup"/>
  14. </apex:actionRegion>
  15. <br/>
  16. <apex:outputPanel id="popup">
  17. <apex:outputPanel id="popInnerOutputPnl" styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
  18. <apex:commandButton value="X" title="Close the popup" action="{!Cancel1}" styleClass="closeButton" >
  19. </apex:commandButton><br/>
  20. <table border="0">
  21. <tr><td>&nbsp;</td></tr>
  22. <tr>
  23. <td align="center">
  24. Additional Notification Recipients(Separate Email Addresses With A Comma)
  25. </td>
  26. <td>
  27.  
  28. </td>
  29. </tr><tr><td>&nbsp;</td></tr>
  30.  
  31. </table>
  32. <table align="center"><tr> <td>&nbsp; </td></tr>
  33. <tr>
  34. <td align="center">
  35. <apex:commandButton id="btnCenter" value="Save & Send" action="{!testingMethod}"> <!-- CALLING THE LOGIC TO CREATE AND ATTACH -->
  36. </apex:commandButton>
  37.  
  38. </td>
  39. </tr>
  40. </table>
  41. </apex:outputPanel>
  42. </apex:outputPanel>
  43. <br/><apex:commandbutton value="Cancel" action="{!Cancel1}" onclick="return myFunction()"/>
  44. </apex:pageblock>
  45. </apex:form>
  46.  
  47. public with sharing class CustomEmailAttachmentsForCampaigns {
  48.  
  49. public CPQ_Notes_Attachments__c cpq1{get;set;}
  50. @AuraEnabled
  51. public static Boolean displayPopup {get;set;}
  52. public CustomEmailAttachmentsForCampaigns() {}
  53. public
  54. CustomEmailAttachmentsForCampaigns(ApexPages.StandardController controller) {
  55.  
  56. }
  57.  
  58. public static transient Attachment myfile;
  59. //public Attachment myfile;
  60. //Getfile Method
  61. public Attachment getmyfile()
  62. {
  63. myfile = new Attachment();
  64. return myfile;
  65. }
  66.  
  67. public void showPopup(){
  68. displayPopup = true;
  69. }
  70.  
  71.  
  72. @AuraEnabled
  73. public static void testingMethod()
  74. {
  75. CPQ_Notes_Attachments__c cpqNotesandAttach;
  76. String idofSC;
  77.  
  78. Sales_Campaign__c newRecord = new Sales_Campaign__c(Name = 'Test account', Account__c = 'Test');
  79. insert newRecord;
  80. idofSC = newRecord.id;
  81. System.debug('TESTING SC ID' + idofSC);
  82. cpqNotesandAttach.Sales_Campaign__c = idofSC;
  83.  
  84.  
  85. Attachment att = new Attachment(parentId = idofSC, name=myfile.name, body = myfile.body);
  86. insert att;
  87. System.debug('TESTING ATT ID' + att.id);
  88. }
  89.  
  90.  
  91. public PageReference Cancel1()
  92. {
  93. displayPopup = false;
  94. return null;
  95. }
  96.  
  97.  
  98. }
Add Comment
Please, Sign In to add comment