+ Start a Discussion

Using a standard controller with and extension on an external site

I am trying to create a case external page that allows for me to use the standard controller with an extension so that they are able to add an attachment if they are wanting to. I had it where it wouldn't upload the attachment and now it will only upload the attachment and leaves all of the data alone. Anyone know of a way for it to do both?

VF Page:
<apex:page standardController="Case" extensions="caseattachment">
    <apex:form id="frm">
        <apex:pageBlock title="New Salesforce Case">
            <apex:pageBlockSection columns="1"  title="Salesforce Case -- Red lines represent required fields." collapsible="false">
            <strong>Please click the lookup icon (small button to right of field) to search name selection from Salesforce lookup dialog.</strong>
            <apex:pageBlockSection columns="1">
               <apex:inputField value="{!Case.Requestor_Name__c}" required="true"/>
            <strong>Select Problem and High Priority ONLY if the issue is preventing you from continuing work in Salesforce.</strong>
            <apex:pageBlockSection columns="1">
               <apex:inputField value="{!Case.Type}" required="true"/>
               <apex:inputField value="{!Case.Priority}" required="true"/>
            <apex:pageBlockSection columns="1" title="Case Details" collapsible="false">
               <apex:inputField value="{!Case.Department__c}" required="true"/>
               <apex:inputField value="{!Case.Salesforce_Object__c}" required="true"/>
               <apex:inputField value="{!Case.Description}" required="true" style="width:50%; height: 60px" />
            <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" value="Submit"/>
               <apex:commandButton action="{!cancel}" value="Cancel"/>
        <apex:pageBlockSection title="Upload the Attachment" collapsible="false" dir="LTR" columns="1">
        <div id="upload" class="upload">                                   
            <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>                            

Apex Class: 
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;
        myAttachment  = new Attachment();
              Integer i=0;
              myAttachment .clear();
              myAttachment.Body = fileBody; 
              myAttachment.Name = 'Logo_'+objcase.id+'.jpeg' ; 
              myAttachment.ParentId = objcase.id;             
              insert myAttachment;                 
        pagereference pr = new pagereference('/'+objcase.id);                           
        return pr;

Anyone know what I am doing wrong? 
Sergio AlcocerSergio Alcocer
Try replacing 
objcase = new case();

objcase = (Case)controller.getRecord();

I changed that line per your recommendation but now it is giving me the error, "Authorization Required 
You must first log in or register before accessing this page. If you have forgotten your password, click Forgot Password to reset it. " I am trying to let this be used as a guest user. Is there a way around this part? 
Sergio AlcocerSergio Alcocer

Have you given the Create rights to the Site guest profile?

Setup > Build > Develop > Sites

Choose yours and "Public Access Settings"

Give rights to create Cases.