+ Start a Discussion
salesforcevicky@gmail.comsalesforcevicky@gmail.com 

trying to Create a Quote for an Opportunity using an Custom Object "Order".

I was trying to Create a Quote for an Opportunity using an Custom Object "Order".we have enabled  Quote for Opportunity  and taken a Custom Object.


We have a  Master Relation ship from Order to Quote .After Creating a Quote it will be generating a Quote Record in Quote we have to Create a createOrder Button so  when we click on the createOrder in Quote it should generate a Record automatically in the Order Object. here is the Code we have Tried with the PageReference but we cannot able to create the Record automatically.


can you please help me out from this,it would be very helpfull................

Class:

Public class CreateOrder
{
//Quote variable q2

public quote q2;

//Create a constructor

public CreateOrder(ApexPages.StandardController cont)

 {
          this.q2 = (Quote)cont.getRecord();
 }

 //Method for creating a order record.


Public pagereference  createorder1()
{
Quote q1=[Select name,quotenumber,email from quote where id=:q2.id];

//creating an order


Order__c  o1= new Order__c();
 o1.name='ParkerOrder';
o1.QuoteNumber__C= q1.QuoteNumber;
insert  o1;

//to navigate currently created order record


Order__C o2=[select id from  Order__c  where id=:o1.id];

PageReference orderhome = new ApexPages.StandardController (o2).edit();
 //PageReference  orderhome = new PageReference('/' +'2F0Q090000000ATox');


orderhome.setRedirect(true);
return orderhome;

}
}



VisualForcePage:

<apex:page standardController="Quote" extensions="CreateOrder" showHeader="false" action="{!createorder1}"> </apex:page>
prady-cmprady-cm

Is the insertion not happening ? or the its not getting redirectred to the new record.