You need to sign in to do that
Don't have an account?

costum controller
Hi,
this is my controller and my apex page:
<apex:page standardController="opportunity" extensions="myControllerExtension">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Information Avenant">
//to display the name of the master opportunity and can edit
<apex:inputField value="{!opportunity.name}"/> <p/>
<apex:outputField value="{!opportunity.N_police_d_origine__c}"/> <p/>
<apex:inputField value="{!opportunity.Date_d_avenant__c}"/> <p/>
<apex:inputField value="{!opportunity.Statut_Police__c}"/> <p/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Enregistrer" action="{!enregistrer}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class myControllerExtension {
private String name;
public Opportunity Opp {get;set;}
public Opportunity OppAcc {get;set;}
ApexPages.StandardController controller;
public myControllerExtension(ApexPages.StandardController c)
{
Opp = (Opportunity)c.getRecord();
}
public PageReference Avenant()
{
return Page.Avenant;
}
public PageReference cancel()
{
PageReference opportunityPage = new ApexPages.StandardController(opp).view();
opportunityPage.setRedirect(true);
return opportunityPage;
}
public PageReference enregistrer() {
//add a news code to crate a new opportunity
}
how to retrieve the data entered in the apex page and create a new opportunity?
thanks.
Try this
All Answers
Hi
Try the below code snippet as reference:
------------- vf page--------------
<apex:page standardController="opportunity" extensions="myControllerExtension">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Information Avenant">
//to display the name of the master opportunity and can edit
<apex:inputField value="{!Opp .name}"/> <p/>
<apex:inputField value="{!Opp .closedate}"/> <p/>
<apex:inputField value="{!Opp .StageName}"/> <p/>
<apex:outputField value="{! Opp.N_police_d_origine__c}"/> <p/>
<apex:inputField value="{! Opp.Date_d_avenant__c}"/> <p/>
<apex:inputField value="{! Opp.Statut_Police__c}"/> <p/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Enregistrer" action="{!enregistrer}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
-------------------------------- apex controller -----------------------
public class myControllerExtension {
private String name;
public Opportunity Opp {get;set;}
public Opportunity OppAcc {get;set;}
ApexPages.StandardController controller;
public myControllerExtension(ApexPages.StandardController c)
{
Opp = (Opportunity)c.getRecord();
}
public PageReference Avenant()
{
return Page.Avenant;
}
public PageReference cancel()
{
PageReference opportunityPage = new ApexPages.StandardController(opp).view();
opportunityPage.setRedirect(true);
return opportunityPage;
}
public PageReference enregistrer() {
insert Opp ;
return null;
//add a news code to crate a new opportunity
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
I have tested this solution and i have this error:
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Name
thanks.
Try this