+ Start a Discussion

I want to convert a custom object to opportunity and line item please help in modifying it.

trigger CreateopportunityonConverted on calllist__c (after insert, after update) {
list<string> callids=new list<String>();
for(callist__c o: trigger.new){
if(o.status__c == converted && o.converted_to_Opp == false){

calllist object fields to be converted into opportunity and opportunity line items.There is a account and opportunity lookup.
While opportunity creation make close date to today and stage to new.There is a secondary owner field which must be filled with calllist record owner in convertion.
calllist[] OLI = [Select UnitPrice, Quantity,OpportunityId, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_opp__c
From OpportunityLineItem
where OpportunityId IN:oppIds and Converted_to_opp__c = false];
Asset[] ast = new Asset[]{};
Asset a = new Asset();
for(OpportunityLineItem ol: OLI){
a = new Asset();
a.AccountId = Trigger.NewMap.get(ol.OpportunityId).AccountId;
a.Product2Id = ol.PricebookEntry.Product2Id;
a.Quantity = ol.Quantity;
a.Price = ol.UnitPrice;
a.PurchaseDate = Trigger.NewMap.get(ol.OpportunityId).CloseDate;

a.Status = 'Purchased';
a.Description = ol.Description;
a.Name = ol.PricebookEntry.Product2.Name;
ol.Converted_to_Assets__c = true;

update OLI;
insert ast;



Thanks in advance