You need to sign in to do that
Don't have an account?
Josh Anderson 30
site.com case with attachment wont insert
I am trying to create a form for public support using the case object and allow for them to add attachments as well. For some reason when I try to submit this nothing is happening. I was wondering if maybe I had my apex incorrect?
VF:
Apex:
VF:
<apex:page Standardcontroller="Case" extensions="attachController" showheader="false" > <html lang="en"> <head> <link href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" rel="stylesheet" media="screen"/> <!-- Bootstrap --> <link href="https://cdn.rawgit.com/creativetimofficial/now-ui-kit/2e8e665f/assets/css/bootstrap.min.css" rel="stylesheet" media="screen"/> <link href="https://cdn.rawgit.com/creativetimofficial/now-ui-kit/2e8e665f/assets/css/now-ui-kit.min.css?v1.2.0" media="screen"/> <title>Submit a Case</title> <style> p, li, .description{ font-weight: 400; line-height: 1.8rem; } .paddingTop{padding-top: 2rem;} } .background-black{background: #2196f3;} .background-black:hover, .background-black:focus{background: #2386d3 !important;} section .section-inner h2{color: #fff;} .round { border-radius: 100px; margin: 0; color: #9a9a9a } .longBox{height: 100px;} @media screen and (max-width: 500px){ .brand .h1-seo{ font-size: 2.2rem; } } </style> </head> <body> <div class="container"> <apex:form > <form class="form-signin"><br/><br/><br/> <br/><h2 class="form-signin-heading">Create a Ticket</h2><br/><br/> <h5 class="form-signin-heading">Email</h5><br/> <apex:inputfield styleClass="inputGroupSelect01 custom-select form-control" value="{!case.Email__c}" required="true"/> <br/><h5 class="form-signin-heading">Subject</h5><br/> <apex:inputfield styleClass="inputGroupSelect01 custom-select form-control" value="{!case.Subject}" required="true"/> <br/><h5 class="form-signin-heading">What are you experiencing?</h5><br/> <apex:inputfield styleClass="inputGroupSelect01 custom-select form-control" value="{!case.What_are_you_experiencing__c}" required="true"/> <br/><h5 class="form-signin-heading">Where is the location of your issue?</h5><br/> <apex:inputfield styleClass="inputGroupSelect01 custom-select form-control" value="{!case.Location_of_issue__c}" required="true"/> <br/><h5 class="form-signin-heading">Source Type</h5><br/> <apex:inputfield styleClass="inputGroupSelect01 custom-select form-control" value="{!case.Source_Type__c}" required="true"/> <br/><h5 class="form-signin-heading">Description</h5><br/> <apex:inputfield styleClass="inputGroupSelect01 custom-select form-control longBox" value="{!case.Description}" required="true"/><br/> <button class="btn btn-primary btn-block btn-lg background-black btn-round round " type="save">Submit</button><br/><br/><br/> <apex:pageBlock > <apex:pageBlockSection title="Upload Attachment" collapsible="false" dir="LTR" columns="1"> <div id="upload" class="upload"> <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/> </div> </apex:pageBlockSection> </apex:pageBlock> </form> </apex:form> </div> <!-- /container --> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> </body> </html> </apex:page>
Apex:
public class attachController { public case objcase{get;set;} public Attachment myAttachment{get;set;} public string fileName{get;set;} public Blob fileBody{get;set;} public attachController(Apexpages.standardcontroller controller) { objcase = (Case)controller.getRecord(); myAttachment = new Attachment(); } public pagereference save() { if(myAttachment.Name == null) { insert objcase; } if(myAttachment.Name != null) { insert objcase; System.debug('@@@@@fileBody'+fileBody); myAttachment = new Attachment(); Integer i=0; myAttachment .clear(); myAttachment.Body = fileBody; myAttachment.Name = fileName ; myAttachment.ParentId = objcase.id; insert myAttachment; } pagereference pr = Page.thankYouForSubmittingYourProductCase; pr.setRedirect(true); return pr; } }