You need to sign in to do that
Don't have an account?
Shawn Reichner
Capturing attachment on Visualforce page
Hoping that one of you awesome Salesforce experts can help me with the following issue I am having.
I have an force.com Site which has a VisualForce page which should open a custom object record on Salesforce. I also have a need to have an attachment added to this VF page to then be attached to the new record being created upon the user pressing save.
Here is what I am seeign so far, if I do not include the Controller extension, the record gets created just fine, but when I have the extension added to the VF page, no record is created.
I am new to apex, so hoping that someone can look over my code below and provide a solution to my frustration :)
Thank you
Shawn
VF Page Code -
First Extention to pass ID of another custom object record and populate a lookup field when record is created.
And lastly, the second controller extension for handling the attachment.
PLEASE HELP!!!!
I have an force.com Site which has a VisualForce page which should open a custom object record on Salesforce. I also have a need to have an attachment added to this VF page to then be attached to the new record being created upon the user pressing save.
Here is what I am seeign so far, if I do not include the Controller extension, the record gets created just fine, but when I have the extension added to the VF page, no record is created.
I am new to apex, so hoping that someone can look over my code below and provide a solution to my frustration :)
Thank you
Shawn
VF Page Code -
<apex:page standardcontroller="Backlog__c" extensions="backlogAttachment,PopulateSchedRelease" showHeader="true"> <img src="{!$resource.AVISPL_Logo2}"></img><b/><b/> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="Software Enhancement Request" columns="1" showHeader="True" collapsible="False"> </apex:pageBlockSection> </apex:pageBlock> <apex:pageMessages /> <apex:pageBlock > <apex:inputField value="{!objcase.Name}"/> <apex:pageBlockSection title="Request/Requestor Information"> <apex:inputfield value="{!objcase.SER_Requestor__c}" required="True"/> <apex:inputfield value="{!objcase.Priority__c}" required="True"/> <apex:inputField value="{!objcase.SER_Requestor_email__c}" required="True"/> <apex:inputfield value="{!objcase.Stakeholder__c}" required="True"/> <apex:inputField value="{!objcase.Requestor_GL_Code__c}"/> <apex:inputfield value="{!objcase.Executive_Sponsor__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Impact of Request"> <apex:inputField value="{!objcase.SER_Category__c}" required="True"/> <apex:inputField value="{!objcase.SER_Sub_Category__c}"/> <apex:inputField value="{!objcase.SER_Designation__c}" required="True"/> <apex:inputField value="{!objcase.Number_of_Users_Affected__c}" required="True"/> <br/> </apex:pageBlockSection> <apex:pageBlockSection title="Request Description Information"> <apex:inputField value="{!objcase.Summary__c}" required="True"/> <apex:inputField value="{!objcase.Reason__c}" required="True"/> <apex:inputField value="{!objcase.Description__c}" required="True"/> <apex:inputField value="{!objcase.Benefit__c}" required="True"/> <br/> </apex:pageBlockSection> <apex:pageBlockSection title="Deadlines and Project Status"> <apex:inputField value="{!objcase.Training_Requirements__c}" required="True"/> <apex:inputField value="{!objcase.Target_Deadline__c}" required="True"/> <apex:inputField value="{!objcase.SOP_Requirements__c}" required="True"/> <apex:inputField value="{!objcase.List_All_U_A_T_Participants__c}" required="True"/> <apex:inputField value="{!objcase.SER_Scheduled_Release__c}"/> <apex:inputField value="{!objcase.Scheduled_Release__c}" rendered="False"/> <br/> </apex:pageBlockSection> <apex:pageBlock title="Upload Attachment"> <apex:inputFile style="width:100%" id="fileToUpload" value="{!objAttachment.Body}" filename="{!objAttachment.Name}" /> </apex:pageBlock> <apex:commandButton value="Submit Request" action="{!saveBacklog}" /> </apex:pageBlock> </apex:form> </apex:page>
First Extention to pass ID of another custom object record and populate a lookup field when record is created.
public class PopulateSchedRelease { public Backlog__c bl; public PopulateSchedRelease(ApexPages.StandardController controller) { this.bl = (Backlog__c)controller.getRecord(); Scheduled_Releases__c sr = getReleaseMethod1(); bl.Scheduled_Release__c = sr.Id; } Scheduled_Releases__c s; public Scheduled_Releases__c getReleaseMethod1() { if(s == null) s = [SELECT Id, Name FROM Scheduled_Releases__c WHERE Name = 'Software Enhancement Request (Default)' LIMIT 1]; return s; } }
And lastly, the second controller extension for handling the attachment.
public class backlogAttachment { public blob getfile{get;set;} public attachment objAttachment{get;set;} public Backlog__c objcase{get;set;} public string filename{get;set;} public backlogAttachment(apexpages.standardcontroller stdCon) { objcase = new Backlog__c(); objAttachment = new Attachment(); } Public PageReference saveBacklog() { insert objcase; objAttachment.body = getfile; objAttachment.ParentId = objcase.Id; objAttachment.name = filename; insert objAttachment; return ApexPages.currentPage(); } }
PLEASE HELP!!!!
use a try-catch block to monitor the exception and use the below code.
All Answers
use a try-catch block to monitor the exception and use the below code.
Thanks again
Shawn