Guest User

Untitled

a guest
Jul 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.61 KB | None | 0 0
  1. <apex:page standardController="Lead" extensions="AddMultipleAttachments" lightningStylesheets="true">
  2.  
  3. <apex:slds />
  4. <div class="slds-scope">
  5.  
  6. <apex:sectionHeader title="Lending Application Edit" subtitle="New Lending Application"/>
  7.  
  8. <style>
  9. body .bPageBlock .pbBody .red .pbSubheader{
  10. background-color:#FAEBD5;
  11. }
  12. body .bPageBlock .pbBody .grey .pbSubheader{
  13. background-color:#c0c0c0;
  14. }
  15. body .bPageBlock .pbBody .grey .pbSubheader h3{
  16. color:#000;
  17. }
  18. </style>
  19.  
  20. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  21.  
  22. <apex:form >
  23.  
  24. <apex:pageBlock title="Lending Application Edit" mode="edit">
  25. <apex:pageBlockButtons location="bottom">
  26. <apex:commandButton value="Save" action="{!save}"/>
  27.  
  28. <apex:commandButton value="Save with Attachments" action="{!createRecordAndAttachments}"/>
  29. <apex:commandButton value="Cancel" action="{!cancel}"/>
  30. <apex:pageMessages />
  31. </apex:pageBlockButtons>
  32.  
  33. <apex:pageBlockSection title="Borrower Info" columns="2">
  34. <apex:inputField value="{!Lead.Company}" required="true"/>
  35. <apex:inputField value="{!Lead.Website}" required="false"/>
  36. <apex:inputField value="{!Lead.FirstName}" required="true"/>
  37. <apex:inputField value="{!Lead.LastName}" required="true"/>
  38. <apex:inputField value="{!Lead.Email}" required="false"/>
  39. <apex:inputField value="{!Lead.Description}" required="false"/>
  40. <apex:inputField value="{!Lead.Phone}" required="false"/>
  41. <apex:pageBlockSectionItem />
  42. <apex:inputField value="{!Lead.MobilePhone}" required="false"/>
  43. <apex:pageBlockSectionItem />
  44. <apex:inputField value="{!Lead.Fax}" required="false"/>
  45. </apex:pageBlockSection>
  46.  
  47. <apex:pageBlockSection title="Address Information" columns="2">
  48. <apex:inputField value="{!Lead.Street}" required="false"/>
  49. <apex:inputField value="{!Lead.City}" required="false"/>
  50. <apex:inputField value="{!Lead.State}" required="false"/>
  51. <apex:inputField value="{!Lead.PostalCode}" required="false"/>
  52. <apex:inputHidden value="{!Lead.Country}" />
  53. <apex:pageBlockSectionItem />
  54. </apex:pageBlockSection>
  55.  
  56. <apex:pageBlockSection title="Property Info" columns="2">
  57. <apex:inputField value="{!Lead.Property_Street_Address__c}" required="true"/>
  58. <apex:inputField value="{!Lead.Property_City__c}" required="true"/>
  59. <apex:inputField value="{!Lead.Property_State__c}" required="false"/>
  60. <apex:inputField value="{!Lead.Property_Zip__c}" required="true"/>
  61. </apex:pageBlockSection>
  62.  
  63. <apex:pageBlockSection title="Loan Info" columns="2">
  64. <apex:inputField value="{!Lead.Amount_of_Request__c}" required="true"/>
  65. <apex:inputField value="{!Lead.Estimated_Value_of_Property__c}" required="true"/>
  66. <apex:pageBlockSectionItem />
  67. <apex:inputField value="{!Lead.Purchase_Price__c}" required="true"/>
  68. </apex:pageBlockSection>
  69.  
  70. <apex:pageBlockSection title="New Section" columns="1" showHeader="false">
  71. <apex:inputField value="{!Lead.Purpose_of_Loan__c}" required="false"/>
  72. </apex:pageBlockSection>
  73.  
  74. <apex:pageBlockSection title="Co-Borrower Info" columns="2">
  75. <apex:inputField value="{!Lead.Co_Borrower1_First_Name__c}" required="false"/>
  76. <apex:inputField value="{!Lead.Co_Borrower1_Last_Name__c}" required="false"/>
  77. <apex:pageBlockSectionItem />
  78. <apex:inputField value="{!Lead.Co_Borrower1_Email__c}" required="false"/>
  79. <apex:inputField value="{!Lead.Co_Borrower2_First_Name__c}" required="false"/>
  80. <apex:inputField value="{!Lead.Co_Borrower2_Last_Name__c}" required="false"/>
  81. <apex:pageBlockSectionItem />
  82. <apex:inputField value="{!Lead.Co_Borrower2_Email__c}" required="false"/>
  83. <apex:inputField value="{!Lead.Co_Borrower3_First_Name__c}" required="false"/>
  84. <apex:inputField value="{!Lead.Co_Borrower3_Last_Name__c}" required="false"/>
  85. <apex:pageBlockSectionItem />
  86. <apex:inputField value="{!Lead.Co_Borrower3_Email__c}" required="false"/>
  87. <apex:inputField value="{!Lead.Co_Borrower4_First_Name__c}" required="false"/>
  88. <apex:inputField value="{!Lead.Co_Borrower4_Last_Name__c}" required="false"/>
  89. <apex:pageBlockSectionItem />
  90. <apex:inputField value="{!Lead.Co_Borrower4_Email__c}" required="false"/>
  91. </apex:pageBlockSection>
  92.  
  93. </apex:pageBlock>
  94. <apex:pageBlock title="Add Attachments">
  95. <apex:outputPanel styleClass="red" layout="block">
  96. <apex:pageBlockSection >
  97. <font color="#000000"><apex:facet name="header">
  98. <span style="color:black">Financial Statement</span>
  99. </apex:facet></font>
  100. <apex:inputFile value="{!attachment1.body}" fileName="{!attachment1.name}"/>
  101. </apex:pageBlockSection>
  102.  
  103. <apex:pageBlockSection >
  104. <font color="#000000"><apex:facet name="header">
  105. <span style="color:black">Attachment 2</span>
  106. </apex:facet></font>
  107. <apex:inputFile value="{!attachment2.body}" fileName="{!attachment2.name}"/>
  108. </apex:pageBlockSection>
  109.  
  110. <apex:pageBlockSection >
  111. <font color="#000000"><apex:facet name="header">
  112. <span style="color:black">Attachment 3</span>
  113. </apex:facet></font>
  114. <apex:inputFile value="{!attachment3.body}" fileName="{!attachment3.name}"/>
  115. </apex:pageBlockSection>
  116. </apex:outputPanel>
  117.  
  118. </apex:pageBlock>
  119.  
  120. </apex:form>
  121.  
  122. </div>
  123. </apex:page>
  124.  
  125.  
  126. public class AddMultipleAttachments {
  127. public Lead objLeadReport { get; set; }
  128. public Attachment attachment1 { get; set; }
  129. public Attachment attachment2 { get; set; }
  130. public Attachment attachment3 { get; set; }
  131. private ApexPages.StandardController controller;
  132.  
  133. public AddMultipleAttachments (ApexPages.StandardController stdController) {
  134. this.controller = stdController;
  135. // Record and Attachments to be inserted
  136. this.objLeadReport = (Lead)(this.controller.getRecord());
  137. this.attachment1 = new Attachment();
  138. this.attachment2 = new Attachment();
  139. this.attachment3 = new Attachment();
  140. }
  141.  
  142. public PageReference createRecordAndAttachments() {
  143. Savepoint sp = Database.setSavepoint();
  144.  
  145. try {
  146. // Insert the record
  147. this.objLeadReport = (Lead)(this.controller.getRecord());
  148. system.debug('var : '+ this.objLeadReport );
  149. insert this.objLeadReport;
  150. system.debug('varId : '+ this.objLeadReport.Id);
  151. // Insert Attachments;
  152. List<Attachment> toInsert = new List<Attachment>();
  153.  
  154. if (this.attachment1.Name != null) {
  155. this.attachment1.ParentId = this.objLeadReport.Id;
  156. toInsert.add(this.attachment1);
  157. }
  158.  
  159. if (this.attachment2.Name != null) {
  160. this.attachment2.ParentId = this.objLeadReport.Id;
  161. toInsert.add(this.attachment2);
  162. }
  163.  
  164. if (this.attachment3.Name != null) {
  165. this.attachment3.ParentId = this.objLeadReport.Id;
  166. toInsert.add(this.attachment3);
  167. }
  168.  
  169. if (!toInsert.isEmpty()) {
  170. insert toInsert;
  171. }
  172.  
  173. } catch(Exception ex) {
  174. Database.rollback(sp);
  175. ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage());
  176. ApexPages.addMessage(msg);
  177. }
  178.  
  179. // View the record
  180. // PageReference page = apexPages.currentPage();
  181. //ApexPages.currentPage();
  182. // page.setRedirect(true);
  183. ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Application successfully submitted.Thank you! /n Please use following Loan Application Id for future uploads or enquiries. ' ));
  184.  
  185. return null;
  186.  
  187.  
  188. }
  189. }
Add Comment
Please, Sign In to add comment