You need to sign in to do that
Don't have an account?
Linda 98
Create opportunity with line items from order
i am having a custom button which opens VF page.and creates opportunity from order and orderitem .I also wan to copy line items of order in to opportunitylineitems.
Plese help.I am having all ready except copying lineitems.
thanks in advance...
Plese help.I am having all ready except copying lineitems.
thanks in advance...
I am assuming you need to create one opportunity per Order, and this happens one Order at a time. Hence I have removed List<Opportunity>.
I have not tested this code, so let me know if you are finding any trouble.
--
Abhi
All Answers
But out of curiosoty, why would you create Order from Opportunity??
This is code which creates opportunity when clicked on custom button which links to a VF page.
But it doesnt create lineitems.I even want to copy line items.
Thank you!!
I am assuming you need to create one opportunity per Order, and this happens one Order at a time. Hence I have removed List<Opportunity>.
I have not tested this code, so let me know if you are finding any trouble.
--
Abhi
Please add, List<OpportunityLineItem> listOI = new List<OpportunityLineItem> (); in line no. 3.
Thanks a lot:)
Yes to fill Lookups, you need to write Apex code (or you go for VisualFlow).
My break was at linking opportunity to order.I have to fill that only when opportunity is created by clicking the button.
i am writing a trigger for that but how can i say that thos opp is created by clicking button without creating any custom fields or any.
thank you
So you will need one lookup in Order pointing to Opportunity and one lookup field in Opportunity pointing to Order.
It would be something like:
newOpp.Order__c = newpage.getId();
....
...
o.Opportunity__c = newOpp.Id;
update o;
Thanks a lot for your support.
I want to do the same stuff from Opportunity (i.e. create Order and Order Line Items from Opportunity).
I have customized your Apex Class where I have replaced Orders with Opportunities and Orders Line Items with Opportunity Line Items to create Order and Order Line Items from Opportunity, which then I have then called it via Visualforce Page, however, I am getting VFPage only with different Tabs but no appropriate results.
Apex Class:-
public with sharing class ConvertOppToOrdersController{
public ApexPages.StandardController newpage;
public ConvertOppToOrdersController(apexpages.standardcontroller stdcontroller) {
this.newpage=stdcontroller;
}
public pagereference createorder() {
Order neworder = new Order();
Opportunity opp = [select StageName,Account.name, CloseDate from Opportunity where Id =:newpage.getId()];
List<OpportunityLineItem> listOI =[select id,unitprice,Description,quantity, PriceBookEntryId from OpportunityLineItem where opportunityid =: newpage.getId()];
neworder.status=opp.StageName;
neworder.Name=opp.Account.Name;
neworder.EffectiveDate=opp.CloseDate;
insert neworder;
for(OpportunityLineItem oi : listOI) {
OrderItem oli = new OrderItem();
oli.orderId = neworder.name;
oli.PriceBookEntryId = oi.PriceBookEntryId;
oli.UnitPrice = oi.UnitPrice;
oli.Description = oi.Description;
oli.Quantity = oi.Quantity;
insert oli;
}
Pagereference pg =new pagereference('/'+neworder.id);
pg.setredirect(true);
return pg;
}
}
VF Page:-
<apex:page standardController="Opportunity" extensions="ConvertOppToOrdersController">
</apex:page>