Created
February 22, 2017 14:58
-
-
Save nithesh1992/07b29b31fed62d67e8dc7bf76036aece to your computer and use it in GitHub Desktop.
Helper Class for copyOppLineItems Trigger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class copyOppItemHelper { | |
public static List<Id> getOppIds(List<Order> orderList) { | |
List<Id> oppIds = new List<Id>(); | |
for(Order newOrder: orderList) { | |
oppIds.add(newOrder.OpportunityId); | |
} | |
return oppIds; | |
} | |
public static List<OpportunityLineItem> getOppItemList(List<Id> oppIds) { | |
List<OpportunityLineItem> oppItemList = [SELECT Id, Description, | |
IsDeleted, ListPrice, Name, OpportunityId, Product2Id, PricebookEntryId, | |
ProductCode, Quantity, ServiceDate, TotalPrice, UnitPrice | |
FROM OpportunityLineItem WHERE IsDeleted = false AND OpportunityId IN :oppIds]; | |
return oppItemList; | |
} | |
public static List<OrderItem> getOrderItemList(List<Order> orderList, List<OpportunityLineItem> oppItemList) { | |
List<OrderItem> orderItemList = new List<OrderItem>(); | |
for(Order nOrder: OrderList) | |
{ | |
for(OpportunityLineItem item: oppItemList){ | |
if(nOrder.OpportunityId == item.OpportunityId) { | |
OrderItem newItem = new OrderItem(); | |
newItem.EndDate = nOrder.EndDate; | |
newItem.OrderId = nOrder.Id; | |
newItem.Description = item.Description; | |
newItem.Quantity = item.Quantity; | |
newItem.UnitPrice = item.UnitPrice; | |
newItem.PricebookEntryId = item.PricebookEntryId; | |
//newItem.ListPrice = item.ListPrice; //not writable | |
//newItem.Product2Id = item.Product2Id; //not writable | |
//newItem.ServiceDate = ?? // Which Date to give? | |
orderItemList.add(newItem); | |
} | |
} | |
} | |
return orderItemList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment