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
Josh Anderson 30Josh Anderson 30 

case with attachments will not create record or attachment

I am trying to create an external site that will allow our customers to be able to submit a case with attachments. When I select the submit button it will go to the redirect on the end of Apex and then push to the new visual force page. No record is then created in my org but at the same time, I am not getting any errors. If I remove the attachment feature or wrap the submission prior to the attachments in its own form then it will create the record. Not sure what I might be doing wrong here. 

VF: 
<apex:page Standardcontroller="Case" extensions="attachController" showheader="false" >
    <html lang="en">
        <head>
            <link rel="icon" type="image/png" href="{!$Resource.siteLogo}" />
            <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 styleclass="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/>
                        <apex:commandButton action="{!submit}" value="Submit" styleClass="btn btn-primary btn-block btn-lg background-black btn-round round"/><br/>
                        <!-- <button class="btn btn-primary btn-block btn-lg background-black btn-round round " action="{!submit}">Submit</button><br/><br/><br/> -->
                    <apex:pageBlock >
                            <apex:pageBlockSection columns="1" >
                                <div id="upload" class="upload">  
                                    <h6>
                                        If you have more than 1 file to upload please zip file to include all files. 
                                    </h6>
                                    <apex:inputFile title="Choose File" value="{!filebody}" filename="{!filename}" styleClass="btn btn-primary btn-block btn-lg background-black btn-round round"/>                            
                                </div>
                            </apex:pageBlockSection>
                        </apex:pageBlock>
                </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 submit(){
        if (myAttachment.Name != null){
            objcase.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Product Case').getRecordTypeId();
            insert objcase;
        }
        if(myAttachment.Name != null){
            objcase.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Product Case').getRecordTypeId();
            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;
    }
}