+ Start a Discussion
Huy NguyenHuy Nguyen 

how to add file to the custom page

Hi all,

I have a page below with the field the file to be attached when save record. Can anyone help me ?

<apex:page controller="LobbyEditRelatedContactController" tabStyle="Clients_Employees__tab" title="Clients & Employees">
    
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"/>
    
    <script>
        
        $(document).ready(function() {
        $("#GvCHX").click(function() {
            $("#GvCHXDetails").toggle(this.checked);
        }).triggerHandler('click');
    });
    
    </script>
    
    <div id="GvCHXDetails">test</div>
    
    <apex:form >
        <apex:pageBlock title="Client"  rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Client']}">
            <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!Contacts.contact.Lobbyists_Appointment__c}"/>
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!Contacts.contact.Client_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="ABN">
                    <apex:inputField value="{!Contacts.contact.ABNUSER__c}"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable" immediate="true">
                        <apex:param name="toDelIdent" value="{!Contacts.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlock>
        <apex:pageBlock title="Employee" rendered="{!$CurrentPage.parameters.RecordType==recordTypesMap['Employee']}">
            <apex:pageBlockTable value="{!lstContacts}" var="Contacts" id="wtable1">
                <apex:column headerValue="Appointment">
                    <apex:inputField value="{!Contacts.contact.Lobbyists_Appointment__c}" />
                </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!Contacts.contact.Employee_NameUSER__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="Position">
                    <apex:inputField value="{!Contacts.contact.Position__c}"/>
                </apex:column>
                <apex:column headerValue="NSW Gov board ?">
                    <apex:inputCheckbox id="GvCHX" value="{!Contacts.contact.Government_Board_or_Committee_Member__c}" immediate="true"/>
                </apex:column>
                <apex:column headerValue="Details">
                    <apex:inputField id="GvCHXDetails" label="details" value="{!Contacts.contact.Details__c}"/>
                </apex:column>
                <!--<apex:column headerValue="Active">
<apex:inputCheckbox value="{!Contacts.cont.Active__c}" />
</apex:column>--> <!--this will be defaulted to TRUE on any new entry-->
                <apex:column headerValue="Add Declaration">
                    <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
                </apex:column>
                <apex:column headerValue="Action">
                    <apex:commandButton value="Delete" action="{!delRow}" rerender="wtable1" immediate="true">
                        <apex:param name="toDelIdent" value="{!Contacts.ident}" assignTo="{!toDelrow}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable1" immediate="true">
                <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable1" immediate="true">
                <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}"/>
     
        </apex:pageBlock>
    </apex:form>
</apex:page>
sandeep sankhlasandeep sankhla
Hi Huy,

What exactly you need here ? Attaching a file means you want to upload csv file or attach means where you want to store ?
Thanks
Sandeep
Huy NguyenHuy Nguyen
hi i want to attach and save it in the record(note and attachment )