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
Siva Raghava Krishna GSiva Raghava Krishna G 

How to upload an Attachment in Site.com Form?

How to upload an attachment in a standard obeject in a Site.com Form
EnreecoEnreeco
Hi Siva,
use the standard apex:inputFile component (https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inputFile.htm), and assign its attributes in this way:
<apex:form>
    <apex:pageMessages />
    <apex:inputFile fileName="{!fname}" contentType="{!cType}" value="{!fileBody}" />
    <apex:button value="Save" action="{!saveFile}" />
</apex:form>

In the controller:
public String fname{get;Set;}
public String cType{get;Set;}
public Blob fileBody{get;Set;}

//you have this object loaded previously
public Account acc{get;set;}

public void saveFile(){
  try{
    Attachment att = new Attachment(Name = this.fname,
                                    ContentType = this.cType,
                                    Body = this.fileBody,
                                    ParentId = this.acc.Id);
    insert att;
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.SUCCESS, 'Attachment uploaded'));
    //this is necessary to avoid the increase in the page's view state
    this.fileBody = null;
  }catch(Exception e){
     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
  }
}

Hope this helps
--
May the Force.com be with you!
EnreecoEnreeco
BTW the "this.fileBody = null;" should be present also in the "catch" part (or outside the try)