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
DannyK89DannyK89 

Adding an Attachment to a visual force page.

I would like to add an attachments section to my custom visual force page. I would also like to display the attachment on the next page.  Here is what I have so far. Please steer me in the right direction

 

 

<apex:page controller="leadController" tabStyle="Referral__c">
    <script>
        function confirmCancel() {
            var isCancel = confirm("Are you sure you wish to cancel?");
            if (isCancel) return true;
  
        return false;
        }
    </script>
    <apex:sectionHeader title="Lead Informaiton" subtitle="Step 2 of 3"/>
    <apex:relatedList list="NotesAndAttachments"/>
    <apex:form >
    <apex:pageBlock title="Candidate Information" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!Leadstep3}" value="Next"/>
            <apex:commandButton action="{!Leadstep1}" value="Previous"/>
            <apex:commandButton action="{!leadcancel}" value="Cancel"
                                onclick="return confirmCancel()" immediate="true"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Candidate Information">
            <apex:inputField id="candidateName" value="{!referral.Candidate_Name__c}"/>
            <apex:inputField id="candidateEmail" value="{!referral.Candidate_Email__c}"/>
            <apex:inputField id="candidatecellPhone" value="{!referral.Candidate_Cell_Phone__c}"/>
            <apex:inputField id="candidateCity" value="{!referral.Candidate_City__c}"/>
            <apex:inputField id="candidateState" value="{!referral.Candidate_State__c}"/>
            <apex:inputField id="areaofExperties" value="{!referral.Area_of_Expertise__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bblaybblay

I think it should work pretty much the same way if it's an image or a Word document.

 

You might want to try these links. They might actually be more helpful than uploading my code since they are more simpler since I have several other things in mine that might make it a bit more confusing such as limit the upload size of an image as well as allow users to only upload 7 pictures. 

 

http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/

 

http://salesforcetrekbin.blogspot.com/2010/04/visualforce-file-upload-for-any-sobject.html

 

Let me know if this helps or you need any other ideas!

 

I should also mention, maybe you already knew or figured, but each attachment must be associated with a record in the URL like www.mydomain.com/page?id={object__c.id}

All Answers

bblaybblay

Maybe this will help some... This page allows users to upload an image attachment and then after uploading an image the page just automatically refreshes and a thumbnail of the image is displayed. Do you also need the controller, or were you just looking for how to do it in VF?

 

 

<apex:form id="a">  
 
<apex:pageBlock > 
<apex:pageMessages id="error"/> 
<apex:inputFile id="b" value="{!fileBody}" filename="{!fileName}"/> 
<br/><br/>
<apex:commandButton value="Upload Image" action="{!UploadFile}" /> <br/>
</apex:pageBlock>  
         
<apex:pageBlock >                               
<apex:repeat value="{!Member__c.attachments}" var="attachment"> 
<img style="border: 1px black solid;" src="{!URLFOR($Action.Attachment.Download, attachment.Id)}" width="100" height="100"/>
</apex:repeat>                                
</apex:pageBlock>
         
</apex:form>

 

 

DannyK89DannyK89

I was looking for a way to upload a word object. If that makes a diffence also a controller would help. 

bblaybblay

I think it should work pretty much the same way if it's an image or a Word document.

 

You might want to try these links. They might actually be more helpful than uploading my code since they are more simpler since I have several other things in mine that might make it a bit more confusing such as limit the upload size of an image as well as allow users to only upload 7 pictures. 

 

http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/

 

http://salesforcetrekbin.blogspot.com/2010/04/visualforce-file-upload-for-any-sobject.html

 

Let me know if this helps or you need any other ideas!

 

I should also mention, maybe you already knew or figured, but each attachment must be associated with a record in the URL like www.mydomain.com/page?id={object__c.id}

This was selected as the best answer