0

I have a trigger After insert on OrderItem.

This Trigger should insert automatically dependents product in the order .

My Problem is that I don't understand how I can efficiently set the PriceBookEntry in this new OrderItem.

Since the context can get orderItems from differents Order with different pricebook, I cannot create map<id,Pricebook>.

this is what I have but it is not efficient.

// Map<PriceBookId,Map<ProductId,PricebookEntry>>
private static Map<Id,Map<Id,PricebookEntry>> getPriceBookEntriesByProductAndPriceBookMap (List<OrderItem> orderItems,Set<id> relevantProductIds,Set<id> relevantPriceBookIds){

    Map<Id,Map<Id,PricebookEntry>> priceBookEntriesByProductAndPriceBookMap = new Map<Id,Map<Id,PricebookEntry>>();

    List<PriceBookEntry> pbs = [SELECT id FROM PriceBookEntry WHERE Product2Id IN : relevantProductIds AND PriceBook2Id IN :relevantPriceBookIds ];
        
    // populate the map 
    
    return priceBookEntriesByProductAndPriceBookMap;

}

Do you have any recommendations or any Idea how I could efficiently set the PriceBookEntry?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.