+ Start a Discussion
A chauhanA chauhan 

what should be the class code for storing Account name (lookup) value in opportunity object with custom controller

vf page
<apex:page id="Request_Page" showHeader="true" controller="Request_Page" >
<apex:outputLabel value="Account Name :" for="AccountName"/>                                   
<apex:inputField id="Account" value="{!Opp.AccountId}" label="AccountName"/> 
<apex:commandButton style="float:right" action="{!requestform}" value="{!$Label.site.submit}" id="submit"/>    

apex code

 public PageReference requestform() {
       
   // objAttachment = new Attachment();
    Opportunity Opp = new Opportunity();
    Opp.Name = RequestName;
    Opp.Type = btype;    
    opp.nextStep = nextStep;
    Opp.StageName = stagedata;
    Opp.Scope_of_Initiative__c = stage;
    Opp.Assign_To__c = stageuser;
    Opp.Description = description;
    Opp.CloseDate = closeDate;
    Opp.Customer_Name__c= CustomerName; 
           
    listOpportunities.add(Opp);
        
   if (listOpportunities.isEmpty() == false) {
        Database.insert(listOpportunities);
       
i want to store value in account name (lookup) in opportunity object

 
Harish RamachandruniHarish Ramachandruni
Hi,

add below line this variable in apex class 

public Opportunity Opp {get;set;}

add below line  this instance in your constracter 

Opp = new Opportunity();

disable line in methode 


Opportunity Opp = new Opportunity();
or 



upadte(copy past  below toatl class 


public class Request_Page{


public Opportunity Opp {get;set;}

public Request_Page(){


}



public PageReference requestform() {
       
   // objAttachment = new Attachment();
   // Opportunity Opp = new Opportunity();
    Opp.Name = RequestName;
    Opp.Type = btype;    
    opp.nextStep = nextStep;
    Opp.StageName = stagedata;
    Opp.Scope_of_Initiative__c = stage;
    Opp.Assign_To__c = stageuser;
    Opp.Description = description;
    Opp.CloseDate = closeDate;
    Opp.Customer_Name__c= CustomerName; 
           insert opp ;

}


}



Any issue ask me ,



Regards ,
Harish.R