+ Start a Discussion
A chauhanA chauhan 

How to access an store Account Name(lookup) through Visualforce page in opportunity object using custom controller ?

i have visualforce pgae called request_page which stores all values in opportubity object like opportunity name,stage,type likewwise i have account anme field on my page but it does not get store in opportunities account name .i want to fetch and store Account Name through my VF Page in the opportunity object i want vf page coding as well as apex class coding 
Manohar kumarManohar kumar

Hi A Chauhan,can you share some of your code?

Thanks,

Manohar

Dileep KumarDileep Kumar

Hi A Chauhan,

First to store AccountName and show this account inside Lookup popup.Please create one lookup field on Opportunity to Account.

E.g. Account_Name__c

VisualForce Page Code:

<apex:page controller="saveOpportunityData">
<apex:form>
    <apex:inputField value="{!opp.Name}"/>
    <apex:inputField value="{!opp.StageName}"/>
    <apex:inputField value="{!opp.CloseDate}"/>
    <apex:inputField value="{!opp.Account_Name__c}"/>
    
    <apex:commandButton value="Submit" action="{!insertOpp}"/>
    
</apex:form>
  
</apex:page>

 

Apex Class Code :

public class saveOpportunityData{
    public Opportunity opp{get;set;}
    public saveOpportunityData(){
        opp = new Opportunity();
         
    }
    public void insertOpp(){
        insert opp;
    }
}

Please try it.If it will useful.please mark it as best answer.

If you will face any problem with this let me know.

Thanks,

Dileep Kumar