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

required="true" for apex:inputFile

Hi All,

I have used required="true" for apex:inputFile.
On click of a custom button, I am trying to upload that file.

But even if its required="true", the controller method is getting called and null pointer exception is being thrown.

We cannot keep rerender in conjuction with rerender attribute. So I am not keeping rerender for this button.

How can check whether a file is selected or not?
Can you post your code,it's still not clear to me ??
kevin Carotherskevin Carothers
Hi Sure@dream,

I tried setting up a simple doc upload and when the doc was blank, the controller threw an error onto my VF page.
The code I used to try to duplicates your problem (although there is no code to duolicate agains) was as follows;

VF page;
<apex:page standardController="Document" extensions="UploaddocumentExt">
    <apex:messages />
    <apex:form id="theForm">
      <apex:pageBlock >
          <apex:pageBlockSection >
            <apex:inputFile required="true"  value="{!document.body}" filename="{!}"/>
            <apex:commandButton value="Save" action="{!save}"/>


public class UploaddocumentExt {
    public UploaddocumentExt(ApexPages.StandardController controller) {
        Document d = (Document) controller.getRecord();
        d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents

This code shows the following errors when you don't specify a file;
User-added image
With "Required="true"  the message in the red rectangle appears.  Without the "required" tag just the message below the rectangle is showing.
Can you give some more detail?