Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <apex:page standardController="Lead" extensions="AddMultipleAttachments" lightningStylesheets="true">
- <apex:slds />
- <div class="slds-scope">
- <apex:sectionHeader title="Lending Application Edit" subtitle="New Lending Application"/>
- <style>
- body .bPageBlock .pbBody .red .pbSubheader{
- background-color:#FAEBD5;
- }
- body .bPageBlock .pbBody .grey .pbSubheader{
- background-color:#c0c0c0;
- }
- body .bPageBlock .pbBody .grey .pbSubheader h3{
- color:#000;
- }
- </style>
- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
- <apex:form >
- <apex:pageBlock title="Lending Application Edit" mode="edit">
- <apex:pageBlockButtons location="bottom">
- <apex:commandButton value="Save" action="{!save}"/>
- <apex:commandButton value="Save with Attachments" action="{!createRecordAndAttachments}"/>
- <apex:commandButton value="Cancel" action="{!cancel}"/>
- <apex:pageMessages />
- </apex:pageBlockButtons>
- <apex:pageBlockSection title="Borrower Info" columns="2">
- <apex:inputField value="{!Lead.Company}" required="true"/>
- <apex:inputField value="{!Lead.Website}" required="false"/>
- <apex:inputField value="{!Lead.FirstName}" required="true"/>
- <apex:inputField value="{!Lead.LastName}" required="true"/>
- <apex:inputField value="{!Lead.Email}" required="false"/>
- <apex:inputField value="{!Lead.Description}" required="false"/>
- <apex:inputField value="{!Lead.Phone}" required="false"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.MobilePhone}" required="false"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.Fax}" required="false"/>
- </apex:pageBlockSection>
- <apex:pageBlockSection title="Address Information" columns="2">
- <apex:inputField value="{!Lead.Street}" required="false"/>
- <apex:inputField value="{!Lead.City}" required="false"/>
- <apex:inputField value="{!Lead.State}" required="false"/>
- <apex:inputField value="{!Lead.PostalCode}" required="false"/>
- <apex:inputHidden value="{!Lead.Country}" />
- <apex:pageBlockSectionItem />
- </apex:pageBlockSection>
- <apex:pageBlockSection title="Property Info" columns="2">
- <apex:inputField value="{!Lead.Property_Street_Address__c}" required="true"/>
- <apex:inputField value="{!Lead.Property_City__c}" required="true"/>
- <apex:inputField value="{!Lead.Property_State__c}" required="false"/>
- <apex:inputField value="{!Lead.Property_Zip__c}" required="true"/>
- </apex:pageBlockSection>
- <apex:pageBlockSection title="Loan Info" columns="2">
- <apex:inputField value="{!Lead.Amount_of_Request__c}" required="true"/>
- <apex:inputField value="{!Lead.Estimated_Value_of_Property__c}" required="true"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.Purchase_Price__c}" required="true"/>
- </apex:pageBlockSection>
- <apex:pageBlockSection title="New Section" columns="1" showHeader="false">
- <apex:inputField value="{!Lead.Purpose_of_Loan__c}" required="false"/>
- </apex:pageBlockSection>
- <apex:pageBlockSection title="Co-Borrower Info" columns="2">
- <apex:inputField value="{!Lead.Co_Borrower1_First_Name__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower1_Last_Name__c}" required="false"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.Co_Borrower1_Email__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower2_First_Name__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower2_Last_Name__c}" required="false"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.Co_Borrower2_Email__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower3_First_Name__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower3_Last_Name__c}" required="false"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.Co_Borrower3_Email__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower4_First_Name__c}" required="false"/>
- <apex:inputField value="{!Lead.Co_Borrower4_Last_Name__c}" required="false"/>
- <apex:pageBlockSectionItem />
- <apex:inputField value="{!Lead.Co_Borrower4_Email__c}" required="false"/>
- </apex:pageBlockSection>
- </apex:pageBlock>
- <apex:pageBlock title="Add Attachments">
- <apex:outputPanel styleClass="red" layout="block">
- <apex:pageBlockSection >
- <font color="#000000"><apex:facet name="header">
- <span style="color:black">Financial Statement</span>
- </apex:facet></font>
- <apex:inputFile value="{!attachment1.body}" fileName="{!attachment1.name}"/>
- </apex:pageBlockSection>
- <apex:pageBlockSection >
- <font color="#000000"><apex:facet name="header">
- <span style="color:black">Attachment 2</span>
- </apex:facet></font>
- <apex:inputFile value="{!attachment2.body}" fileName="{!attachment2.name}"/>
- </apex:pageBlockSection>
- <apex:pageBlockSection >
- <font color="#000000"><apex:facet name="header">
- <span style="color:black">Attachment 3</span>
- </apex:facet></font>
- <apex:inputFile value="{!attachment3.body}" fileName="{!attachment3.name}"/>
- </apex:pageBlockSection>
- </apex:outputPanel>
- </apex:pageBlock>
- </apex:form>
- </div>
- </apex:page>
- public class AddMultipleAttachments {
- public Lead objLeadReport { get; set; }
- public Attachment attachment1 { get; set; }
- public Attachment attachment2 { get; set; }
- public Attachment attachment3 { get; set; }
- private ApexPages.StandardController controller;
- public AddMultipleAttachments (ApexPages.StandardController stdController) {
- this.controller = stdController;
- // Record and Attachments to be inserted
- this.objLeadReport = (Lead)(this.controller.getRecord());
- this.attachment1 = new Attachment();
- this.attachment2 = new Attachment();
- this.attachment3 = new Attachment();
- }
- public PageReference createRecordAndAttachments() {
- Savepoint sp = Database.setSavepoint();
- try {
- // Insert the record
- this.objLeadReport = (Lead)(this.controller.getRecord());
- system.debug('var : '+ this.objLeadReport );
- insert this.objLeadReport;
- system.debug('varId : '+ this.objLeadReport.Id);
- // Insert Attachments;
- List<Attachment> toInsert = new List<Attachment>();
- if (this.attachment1.Name != null) {
- this.attachment1.ParentId = this.objLeadReport.Id;
- toInsert.add(this.attachment1);
- }
- if (this.attachment2.Name != null) {
- this.attachment2.ParentId = this.objLeadReport.Id;
- toInsert.add(this.attachment2);
- }
- if (this.attachment3.Name != null) {
- this.attachment3.ParentId = this.objLeadReport.Id;
- toInsert.add(this.attachment3);
- }
- if (!toInsert.isEmpty()) {
- insert toInsert;
- }
- } catch(Exception ex) {
- Database.rollback(sp);
- ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage());
- ApexPages.addMessage(msg);
- }
- // View the record
- // PageReference page = apexPages.currentPage();
- //ApexPages.currentPage();
- // page.setRedirect(true);
- 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. ' ));
- return null;
- }
- }
Add Comment
Please, Sign In to add comment