1

I want to update custom field "Price_Book_Entry_Floor_Price__c" from Pricebook object (Pricebook2) with value from custom field "Floor_Price__c" from Price book Entry object (PricebookEntry), i have below trigger but something is wrong, i don't see anyother way besides trigger please help

Pricebook2 = parent object PricebookEntry = child object

Trigger:

trigger Updateparent on Pricebook2 (after insert, after update) {

    Map<ID, Pricebook2> parentpricebook = new Map<ID, Pricebook2>();
    List<Id> listIds = new List<Id>();

    for (PricebookEntry childObj : Trigger.new) {
        listIds.add(childObj.Pricebook2);
    }

    parentpricebook = new Map<Id, Pricebook2>([SELECT id,Price_Book_Entry_Floor_Price__c,(SELECT ID, Floor_Price__c FROM PricebookEntry__r) FROM Pricebook2 WHERE ID IN :listIds]);

    for (PricebookEntry pe: Trigger.new) {
        Pricebook2 ppbook = parentpricebook.get(pe.Floor_Price__c);
        ppbook.Price_Book_Entry_Floor_Price__c = pe.Floor_Price__c;
    }

    update parentpricebook.values();
}
0

Your trigger is currently running on PriceBook2 (parent object) not PricebookEntry (child object) and unfortunately salesforce doesn't support triggers on pricebook entry yet.

the better option left for you is to do it as a batch job which takes the value from the pricebook entry and udpates the pricebooks.

here's an idea you can vote up in the meantime

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.