+ Start a Discussion
YashhYashh 

want help in Visualforce page

ill  tell what is doing  this scenario and what i want (please Help)
1 >So here i created Visualforce Page in that i have given some fields so when i save this its shows me on the sales order. This all i created in a standard format.
2>but right now what I want there is an upload button if data will upload then its  sent to the( sales order object there is a child product object) there i want to show. 
So here is My Vf code
<apex:page standardController="Opportunity" sidebar="flase" showHeader="false">
<apex:form >

<apex:pageBlock title="Sales Order">
  <apex:pageBlockSection title="Information" collapsible="false" columns="1">
    <apex:inputField value="{!Opportunity.Name}"/>
    <apex:inputField value="{!Opportunity.CloseDate}"/> 
    <apex:inputField value="{!Opportunity.StageName}"/>
  </apex:pageBlockSection>
 
  <apex:pageBlockSection title="Product">
  
  <apex:commandButton value="Upload File"/>
  
  </apex:pageBlockSection>
 
 <apex:pageBlockButtons location="bottom">
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
 </apex:pageBlockButtons>
 </apex:pageBlock>
</apex:form>
</apex:page>User-added image
mukesh guptamukesh gupta
Hi Yash,

Please follow below example:
<apex:page controller="RegisterandSaveCSVFileClass">
    <apex:form >
        <apex:pageBlock >
            <apex:messages />
            <apex:pageBlockSection columns="2" showHeader="true" title="Project Details" >
                <apex:inputField value="{!newProject.Name}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputfile value="{!attachment.body}" filename="{!attachment.Name}" />
                <apex:commandbutton value="Upload and save" action="{!saveButtonAction}"/>
            </apex:pageBlockSection> 
        </apex:pageBlock> 
    </apex:form>
</apex:page>

Apex class:-
public class RegisterandSaveCSVFileClass {    
    public Project__c newProject {get; set;}
    public Attachment attachment {get;set;}    
    public RegisterandSaveCSVFileClass(){
        newProject = new Project__c();
        attachment = new Attachment();
    }
    public void saveButtonAction(){
        System.debug('newProject.Name'+newProject.Name);
        if(newProject.Name != null){
            insert newProject;               
            if(attachment.Name.endsWith('.csv')){
                attachment.parentid = newProject.id;
                insert attachment;                
            }else{
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'You need to upload only CSV document');
                ApexPages.addMessage(myMsg); 
                return ;
            }
        }
    }    
}

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh