+ Start a Discussion
Jonathan Anspaugh 6Jonathan Anspaugh 6 

Setting variables dynamically from record display

I have a visualforce page with the following code:
<apex:page showHeader="false" sidebar="false" controller="cc_AppChecklist_List" standardStylesheets="false" html-lang="en-US">  
    <c:cc_App_Header />
    <c:cc_App_TopNav activeSection="Personal" />
    <div class="gridlock gridlock-16 appPage">
        <div class="page page_container clearfix"> 
            <div class="row page_row">
                <div class="content page_content max-push-1 max-14 desktop-push-1 desktop-14 tablet-full mobile-full margined">
                    <div class="row page_row content_block background">
                        <div class="desktop-12 tablet-6 mobile-6 min-full left" >
                            <h1 style="margin: 0;">My Application Checklist Items</h1>
                        <apex:pageBlock title=""> 
                            <apex:pageBlockTable value="{!Records}" var="Record" style="width:100%"> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist ID</apex:facet> 
                                    <apex:outputText value="{!Record.Id}"/> 
                                <apex:column style="width:35%"> 
                                    <apex:facet name="header">Checklist Name</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Name__c}"/> 
                                <apex:column style="width:10%"> 
                                    <apex:facet name="header">Status</apex:facet> 
                                    <apex:outputText value="{!Record.CC_Document_Status__c}"/> 
                                <!-- apex:column > 
                                    <apex:facet name="header">Date Requested</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Requested__c}" /> 
                                <apex:column > 
                                    <apex:facet name="header">Date Due</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Due_Date__c}" /> 
                                </apex:column --> 
                                <apex:column style="width:15%"> 
                                    <apex:facet name="header">Date Received</apex:facet> 
                                    <apex:outputText value="{0, date, MMMM d','  yyyy}">
                                        <apex:param value="{!Record.CC_Date_Received__c}" /> 
                                <apex:column style="width:40%"> 
                                    <apex:facet name="header">Action</apex:facet> 
                                    <apex:form >
                                         <apex:inputFile title="file_upload" value="{!file.body}" fileName="{!file.name}" id="file_upload" onchange="return checkFileSize(this);"/>
                                         <apex:commandButton styleClass="btn app-btn-success" value="Upload" action="{!uploadFile}" />

    <!-- <c:App_Footer /> -->

Control class:
public with sharing class cc_AppChecklist_List{ 

    public List<Application_Checklist__c> Records {get; set;} 
    String AppID = ApexPages.currentPage().getParameters().get('appid');
    public cc_AppChecklist_List(){ 
    Records = 
    [SELECT Id, Name, CC_Document_Name__c, CC_Document_Status__c, CC_Date_Received__c,CC_Date_Requested__c, CC_Due_Date__c FROM Application_Checklist__c WHERE Application_CC__c = :AppID];    
    // system.debug('-----ChecklistID')
    // Upload Code
    private Id itemId {get; set;}
    public Application_Checklist__c item {get; set;}
    public SObject obj {get; set;} 
    public Attachment file {
        get {
            if(file == null) {
                file = new Attachment(ParentId = itemId);
            return file;
    private Boolean isOld {get; set;}

    public PageReference uploadFile() {
        PageReference pr = null;
        try {
            insert file;
            if(isOld) {
                item.CC_Date_Received__c = Date.today();
                update item;
            } else {
                obj.put('CC_Date_Received__c', Date.today());
                update obj;
            pr = Page.cc_App_Status;
        } catch (Exception ex) {
        } finally {
            file = null;
        return pr;

What I am trying to do is make the {!Record.Id} value for each row in the visualforce page pass across to the "itemId" value so the upload button will upload to the correct record. The upload function works when I hard code a value but I am having trouble passing the data to the variable when the upload button is selected. The goal of this is to query an application id and display all checklist items on the visualforce page with an upload button for each item. 
Tuan LuTuan Lu
You want to use a apex:param element inside your commandLink element to set a property on controller with the recordId. 
<apex:commandButton styleClass="btn app-btn-success"value="Upload" action="{!uploadFile}" >
<apex:param name="FiletoUpload" value={!Record.Id}" assignTo="{!itemId }"/>

// make this public 
    public Id itemId {get; set;}

Hope this helps ...!!!
Jonathan Anspaugh 6Jonathan Anspaugh 6
That helps set the variable but the upload function still is not attaching the file to the actual record. Any ideas?