1

First Code

<apex:page controller="testpagecontroller">
<apex:pageMessages ></apex:pageMessages>
<apex:form >
    00128000008Z416
    <apex:inputfile value="{!b}"></apex:inputfile>
    <apex:commandButton action="{!saveAtt}" value="save"/>
</apex:form>

Controller:

public class testpagecontroller {
    public attachment att{get;set;}
    public transient blob b{get;set;}
    public testpagecontroller(){
        att = new attachment();
    }
    public void saveAtt(){
        system.debug(b);
        att.parentid = '00128000008Z416';
        att.Name = 'myatt';
        att.body = b;
        insert att;
        att = null;
    }
}

Second code:

<apex:page controller="testpagecontroller">
    <apex:pageMessages ></apex:pageMessages>
    <apex:form >
        00128000008Z416
        <apex:inputfile value="{!att.body}"></apex:inputfile>
        <apex:commandButton action="{!saveAtt}" value="save"/>
    </apex:form>
</apex:page>

Controller:

public class testpagecontroller {
    public attachment att{get;set;}
    public transient blob b{get;set;}
    public testpagecontroller(){
        att = new attachment();
    }
    public void saveAtt(){
        system.debug(b);
        att.parentid = '00128000008Z416';
        att.Name = 'myatt';
        insert att;
        att = null;
    }
}

Above are two codes to upload a file as a on attachment object. The difference is the bind variable, in first code, its a blob while in the second case, its an attachment.body.

As the attachment max size is 25 MB, first code should allow 25 MB file to be uploaded. But it doesn't. For files greater than 10MB, the blob is read null in the contrller.

While the second one works fine and allows upto 25MB file to be uploaded.

It seems that apex:inputfile somehow figures out that blob is for attachment and hence doesn't make the attachment body as null. But is this behavior mentioned in some docs?

Any thoughts are welcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.