function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dwwrightdwwright 

Using <apex:inputFile>

I'd like to set up a field on a visualforce page where users can upload PDF's. I'm having trouble figuring out how to do this with a controller extension. I've got a custom object which is a child object of opportunity. I'm passing the Id of the opportunity to my page as a parameter 'rfq', and attempting to assign that id in the controller to the attachment before inserting it.

public class TechSpecController {

rfqId Id;

Attachment att;

public TechSpecController(ApexPages.StandardController theController){

this.spec = (SDV_Tech_Specification__c) theController.getRecord();
rfqId = ApexPages.currentPage().getParameters().get('rfq');
att = new Attachment();

}

 

public PageReference attach() {
att.ParentId = rfqId;
insert att;
return ApexPages.currentPage();
}

}

 

I'm having trouble tying the <apex:inputFile> to the attachment field. I'm getting the error:  Unknown property 'SDV_Tech_Specification__cStandardController.att'   

 

 

<apex:page standardController="SDV_Tech_Specification__c" extensions="TechSpecController" showHeader="false">

<apex:inputFile value="{!att.body}" filename="{!att.name}"/>
</apex:page>

 

Obviously it's looking for a variable in the standardController, so I guess my question is: Can you use an extension and refer to the fields within that extension in the way I'm trying to? If not, is there another way to do it?

 

 

 

Message Edited by dwwright on 03-04-2010 11:50 AM
bob_buzzardbob_buzzard

Your 'att' property cannot be seen by the page because it has default visibility, which equates to private in Force.

 

Change your declaration to:

 

  public Attachment att {get; set;}

 

and you should be good to go.