You need to sign in to do that
Don't have an account?
jsacpt24
VisualForce Attachment isn't uploading
I am trying to have a site that has a visualforce page allowing someone to upload an attachment with the new record that they are creating. I have the attachment passing at 95% code coverage but it doesn't seem to actually be uploading the attachment with the new record.
VF:
Apex Class:
Wondering if someone might be able to help me figure out what I might be doing incorrect?
VF:
<apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Submit"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <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"/> </div> </apex:pageBlockSection>
Apex Class:
public class dataSheetAttachment { public Data_Feasibility_Request__c objdfr{get;set;} public Attachment myAttachment{get;set;} public string fileName{get;set;} public Blob fileBody{get;set;} public dataSheetAttachment(Apexpages.standardcontroller controller) { objdfr = (Data_Feasibility_Request__c)controller.getRecord(); myAttachment = new Attachment(); } public pagereference save() { if(myAttachment.Name == null) { insert objdfr; } if(myAttachment.Name != null) { insert objdfr; System.debug('@@@@@fileBody'+fileBody); myAttachment = new Attachment(); Integer i=0; myAttachment .clear(); myAttachment.Body = fileBody; myAttachment.Name = fileName ; myAttachment.ParentId = objdfr.id; insert myAttachment; } pagereference pr = Page.Thank_You; pr.setRedirect(true); return pr; } }Test Class:
@isTest private class Test_dataSheetAttachment { public static testMethod void validatedataSheetAttachment() { Data_Feasibility_Request__c myDFR = new Data_Feasibility_Request__c(); dataSheetAttachment pageController = new dataSheetAttachment(new ApexPages.StandardController(myDFR)); pageController.myAttachment.Name = 'foo'; pageController.fileBody=Blob.valueOf('Body Test'); pageController.fileName = 'Test'; pageController.save(); } }
Wondering if someone might be able to help me figure out what I might be doing incorrect?
Let us know if this will help you
All Answers
Let us know if this will help you
1) http://bobbuzzard.blogspot.in/2011/01/uploading-multiple-attachments-via.html