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

how to add more than one opportunity to existing account using Vf page and Apex

Hi All, In my custom object i have created a  VF page in that I have created a lookup field for "Account" which will display all my existing Account. Also i have created a picklist field for Opportunity(for example i have given 10 values). In the same page i have created a button "convert" when i click the "convert" it must create a new opportuinty to that Account which i have selected. Here i have apex code and Vf page code for this. Kindly tell me how to do this.



public class Conversion_site
private final Site__c Acc_site; //User sobject
private Site__c siteObj;
public Account t{get;set;}
public PageReference RedirecttoSite()
String currentLead = '/' + siteObj.Id;
PageReference pageRef = new PageReference(currentLead);
return pageRef;

// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public Conversion_site(ApexPages.StandardController stdController)
this.Acc_site = (Site__c)stdController.getRecord();
siteObj = (Site__c)stdController.getRecord();
t =new Account();


//creating Opportunity1 picklist values
String s1='Timber';
public String getString1()
return s1;
public void setString1(String s1 )
this.s1 = s1;



VF page Code:


<apex:page standardController="Site__c" cache="true" extensions="Conversion_site">
<apex:form >

<apex:pageBlock title="Convert {!} " >


<!-- Opportunity1 ,Account 1 ,Sales Person1-->
<apex:pageBlockSectionItem >
<apex:outputLabel value="1"/>
<apex:selectList label="1" value="{!string1}" size="1" required="true">
<apex:selectOption itemValue="Timber" itemLabel="Timber"/>
<apex:selectOption itemValue="Plasterboard & Villaboard" itemLabel="Plasterboard & Villaboard"/>
<apex:selectOption itemValue="Steel Products" itemLabel="Steel Products"/>
<apex:selectOption itemValue="Power Tools" itemLabel="Power Tools"/>
<apex:selectOption itemValue="Sand & Gravel" itemLabel="Sand & Gravel"/>
<apex:selectOption itemValue="Cement & Concrete" itemLabel="Cement & Concrete"/>
<apex:selectOption itemValue="Safety Equipment" itemLabel="Safety Equipment"/>
<apex:selectOption itemValue="Equipment Hire" itemLabel="Equipment Hire"/>

<apex:pageBlockSectionItem >
<apex:inputField value="{!t.Parentid}"/>