I'm new to SF and trying to write a custom case controller that adds an attachment to a case.
I've simplified my apex code below. I'm guessing I need to do a.OwnerId = UserInfo.getUserId(); to get the attachment to show up under the user's case list?
I would like to delete an attachment I used for a test but I can't find it.
public class MyCaseController {
public Case c { get; set; }
public Attachment a { get; set; }
public MyCaseController() {
c = new Case();
a = new Attachment();
}
public PageReference save() {
try {
INSERT c;
if (a.BodyLength > 0)
{
a.ParentId = c.Id;
INSERT a;
}
return new PageReference('/apex/Thanks');
} catch (Exception e) {
ApexPages.addMessages(e);
return null;
}
}
<apex:page controller="MyCaseController" sidebar="False" showHeader="False">
<apex:form >
<apex:pageMessages ></apex:pageMessages><br />
<apex:commandButton action="{!save}" value="Submit"/><br /><br />
Issue type:<br />
<apex:inputfield value="{!c.type}" required="true"/><br />
Issue priority:<br />
<apex:inputField value="{!c.priority}"/><br />
Subject:<br />
<apex:inputField value="{!c.Subject}" required="true"/><br />
<apex:inputTextarea value="{!c.description}" rows="20" cols="20" /><br />
Attachment:<br />
<apex:inputFile value="{!a.body}" filename="{!a.name}" id="file"/>
</apex:form>
</apex:page>