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
hmoh1920hmoh1920 

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.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
DoomsdayDoomsday
public myControllerExtension(ApexPages.StandardController c)
{
   Opp = [SELECT Name, N_police_d_origine__c, Date_d_avenant__c, Statut_Police__c FROM Opportunity WHERE Id=:c.getRecord().Id];
}

 

Try this

 

All Answers

Navatar_DbSupNavatar_DbSup

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. 

hmoh1920hmoh1920

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.

DoomsdayDoomsday
public myControllerExtension(ApexPages.StandardController c)
{
   Opp = [SELECT Name, N_police_d_origine__c, Date_d_avenant__c, Statut_Police__c FROM Opportunity WHERE Id=:c.getRecord().Id];
}

 

Try this

 

This was selected as the best answer