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
James KinseyJames Kinsey 

VF Page that creates new opportunity in edit mode...

Hello,

 

I am new and seeking out how to code a VF page to insert a new opportunity and show this new opportunity in the edit mode before inserting (saving).

 

Thanks,

 

- James -

James KinseyJames Kinsey

Here is my extension...

public class newczi {
    public Equipment__c e {get;set;}
    public newczi(ApexPages.StandardController controller) {
            e = [select id, name, Next_CZI_Date__c from equipment__c where Id = :ApexPages.currentPage().getParameters().get('id')];
                     }
       public PageReference NewOpp(){
        Opportunity o = new Opportunity(name = e.name,StageName='New Opportunity',CloseDate=system.today());
        Database.SaveResult[] lsr = Database.insert(new Opportunity[]{o, new Opportunity(name = 'name',StageName='New Opportunity',CloseDate=system.today())},false);
        for(Database.SaveResult sr: lsr){
            if(!sr.isSuccess())
                Database.Error err = sr.getErrors()[0];
        }
                return (new ApexPages.StandardController(o)).edit();

        }   
}

 

I believe that this will create the new opportunity but how do I tell the VF page to open this newly created opportunity in edit mode?

Pradeep_NavatarPradeep_Navatar

Find below a sample code :

<apex:page standardController="opportunity  ">
<apex:form>
 <apex:pageBlock>
<apex:pageBlockButton>
  <apex:commandButton value="Save" action="{!save}"/>
 <apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButton>
   <apex:pageBlockSection>
       <apex:pageBlockSectionItem>
           <apex:inputField value="{!opportunity.name}" />

               // Here you can bind other field of opportunity like as given above
               // and don't need to write apex code for saving and all that, just bind fields

       </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

James KinseyJames Kinsey

Thank you for the post!

This does develop a screen for field input with a save button, but I cannot input a value from my custom object, equipment__c, which I was attempting to have my controller extension get the data from. 

// EX: <apex:inputfield value ="{!opportunity.amount}"/>    but here have a field from my custom object already input in this field and in edit mode.

Also I cannot input this VF Page on my custom object as a custom button or link.  I believe that since this page is using the opportunity controller i cannot use it on a custom object.  So then the question is how do I create this VF page using the equipment__c standard controller and still have it get the equipment data and populate a new opportunity in edit mode?

 

And one last thing... Which came first, the chicken or the egg....?

:)

Thanks in advance!