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
RuduRudu 

Hi....please help about VF page...I have create a Account and Contact Detail pages wizard also save save simultaneously....but i want to upload a photo for contact profile....

Create a VF Page wizard. This wizard will have two pages.First Page will let user enter Account details.Second Page will let user enter Contact Details: Contact Name, Department, Birthdate, Phone, Mobile, Email. Additionally Contact page will provide ability to upload Contact photo.Save button will be available only on the second page. On click of save first create Account record then create contact record and link it with Account. this is the my whole requirment....i complete all code but i am facing issue in  Contact page will provide ability to upload Contact photo
public class newOpportunityController {

   // These four member variables maintain the state of the wizard.
   // When users enter data into the wizard, their input is stored
   // in these variables. 
   Account account;
   Contact contact;
  
   // The next four methods return one of each of the four member
   // variables. If this is the first time the method is called,
   // it creates an empty record for the variable.
   public Account getAccount() {
      if(account == null) account = new Account();
      return account;
   }

   public Contact getContact() {
      if(contact == null) contact = new Contact();
      return contact;
   }

  

   // The next three methods control navigation through
   // the wizard. Each returns a PageReference for one of the three pages
   // in the wizard. Note that the redirect attribute does not need to
   // be set on the PageReference because the URL does not need to change
   // when users move from page to page.
   public PageReference step1() {
      return Page.opptyStep1;
   }

   public PageReference step2() {
      return Page.opptyStep2;
   }

 
    public PageReference cancel() {
			PageReference opportunityPage = new ApexPages.StandardController(Contact).view();
			opportunityPage.setRedirect(true);
			return opportunityPage; 
    }

   // This method performs the final save for all four objects, and
   // then navigates the user to the detail page for the new
   // opportunity.
   public PageReference save() {

      // Create the account. Before inserting, copy the contact's
      // phone number into the account phone number field.
      account.phone = contact.phone;
      insert account;

      // Create the contact. Before inserting, use the id field
      // that's created once the account is inserted to create
      // the relationship between the contact and the account.
      contact.accountId = account.id;
      insert contact;


      PageReference opptyPage = new ApexPages.StandardController(Contact).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }
    public blob file { get; set; }
      public PageReference upload()
    {
      
        ContentVersion v = new ContentVersion();
        v.versionData =file;
        v.title = 'testing upload';
        v.pathOnClient ='/somepath.jpg / somepath.png';
        insert v;
        return new PageReference('/' + v.id);
    }

}





Vf pages:-opptyStep1

<apex:page controller="newOpportunityController" tabStyle="Account">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
      return false;
  }  
  </script>
  <apex:sectionHeader title="Edit Account" subtitle="New Account"/>
    <apex:form >
      <apex:pageBlock title="Account Information" mode="edit">

        <!-- The pageBlockButtons tag defines the buttons that appear at the top
             and bottom of the pageBlock. Like a facet, it can appear anywhere in
             a pageBlock, but always defines the button areas.-->
        <!-- The Next button contained in this pageBlockButtons area
             calls the step2 controller method, which returns a pageReference to
             the next step of the wizard. -->
        <apex:pageBlockButtons >
          <apex:commandButton action="{!step2}" value="Next"/>
          <apex:commandButton action="{!cancel}" value="Cancel" 
                              onclick="return confirmCancel()" immediate="true"/>
        </apex:pageBlockButtons>
          
      <apex:pageBlockSection title="Account Inpformation">

        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->
         
        <apex:inputField id="AccountName" value="{!account.Name}" required="true"/>
        <apex:inputField id="AccountType" value="{!account.Type}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Address Information">
          <apex:inputField value="{!Account.BillingStreet}"/>
          <apex:inputField value="{!Account.BillingCity}"/>
            <apex:inputField value="{!Account.ShippingStreet}"  required="true"/>  
            <apex:inputField value="{!Account.ShippingCity	}" required="true"/>
           <apex:inputField value="{!Account.ShippingState}" required="true"/>
           <apex:inputField value="{!Account.ShippingPostalCode}" required="true"/>
           <apex:inputField value="{!Account.ShippingCountry}" required="true"/>
           </apex:pageBlockSection>
          <apex:pageBlockSection title="Additional Information">
          <apex:inputField value="{!Account.Website}"/>
          <apex:inputField value="{!Account.Industry}"/>
          <apex:inputField value="{!Account.Phone}"/>
            <apex:inputField value="{!Account.Fax}"/>
            <apex:inputField value="{!Account.Description}"/>
        
     </apex:pageBlockSection>
     
          
    </apex:pageBlock>
  </apex:form>
</apex:page>



Second Page:-opptyStep2

<apex:page controller="newOpportunityController" tabStyle="Contact">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
  
     return false;
  }  
  </script>
  <apex:sectionHeader title="New Contact" subtitle="Step 2 of 3"/>
  <apex:form >
    <apex:pageBlock title="Contact Information" mode="edit">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!step1}" value="Previous"/>
        <apex:commandButton action="{!Save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel" 
                            onclick="return confirmCancel()" immediate="true"/>
      </apex:pageBlockButtons>
     <apex:pageblocksection title="Contact Information">
     <apex:inputField value="{!Contact.FirstName}"/>
     <apex:inputField value="{!Contact.LastName}"/>
          <apex:inputField value="{!Contact.Department}"/>
          <apex:inputField value="{!Contact.Birthdate}"/>
          <apex:inputField value="{!Contact.Phone}"/>
          <apex:inputField value="{!Contact.MobilePhone}"/>
          <apex:inputField value="{!Contact.Email}"/>
         
            <apex:inputFile value="{!file}" />
 <apex:commandbutton action="{!upload}" value="upload" />


      </apex:pageblocksection>
    </apex:pageBlock>
  </apex:form>
</apex:page>