+ Start a Discussion
Shawn ReichnerShawn Reichner 

Help with Site VisualForce Page Not Populating fields on Case Record

Hello,

I am building a "Site" for guest users to submit a Case for support.  I have the site built, the visualforce page, and a controller extension built to add an attchment.  When the case is submitted form the site, it creates a Case record in Salesforce, the attachment shows under the notes and attachments related list, but the subject and description fields that were filled out on the Site are not being populated on the case record.  

I am at a loss here as to why they are not working, and I am a new developer so I very well could have missed something very easy.  Please look over the following code for my VF Page, and the controller extension, and if available please help me figure out how to get the subject and description fields to populate on the case record with the information that was submitted via the site submission.  

Thank you in advance for your time and help!

VF Page

<apex:page standardcontroller="Case" extensions="caseattachment"
showHeader="false">
<img src="{!$resource.AVISPL_Logo2}"></img><b/><b/>
    <apex:form >
    <apex:pageBlock >
<apex:pageBlockSection title="Hello, Thank You For Reporting Your Incident!  A Salesforce Platform Engineer Will Be In Touch Shortly. " columns="1" showHeader="True" collapsible="False">
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageMessages />

        <apex:pageBlock >
        <apex:inputField value="{!Case.CaseNumber}"/>
            <apex:pageBlockSection title="Subject">
                <apex:inputText value="{!Case.subject}" />
            </apex:pageBlockSection>

            <apex:pageBlockSection title="Attachment Or ScreenShot">                                   
            <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>                            
            
            </apex:pageBlockSection>

            <apex:pageBlockSection title="Tell Us About The Incident">
                <apex:inputTextarea value="{!Case.Description}" rows="8" cols="80" />
            </apex:pageBlockSection>

            <apex:commandButton value="Submit Incident" action="{!Save}" />
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller extension

public class caseattachment
{
public case objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;} 
public Blob fileBody{get;set;}

    public caseattachment(Apexpages.standardcontroller controller)
    {
        objcase = new case();
        myAttachment =new Attachment();
    }
    public pagereference save()
    {
        insert objcase;
        System.debug('@@@@@fileBody'+fileBody);     
        myAttachment  = new Attachment();
              Integer i=0;
              myAttachment .clear();
              myAttachment.Body = fileBody;
              myAttachment.Name = this.fileName; 
              myAttachment.ParentId = objcase.id;             
              insert myAttachment;                 
        pagereference pr = new pagereference('/'+objcase.id);                           
        return pr;
    }
}
bob_buzzardbob_buzzard
The problem here is that you are saving the 'objcase' record in your controller, but the input fields on the page are bound to the 'Case' record from the standard controller.

I wouldn't use the standard controller myself - instead I'd convert your extension controller to a custom controller and bind the fields on the page to the objcase record.