function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave The RaveDave The Rave 

price book entry object - automation update field

Price Book Entry object -  update custom field when record created or edited

Normally, I would start with the process builder. However, the object is not available in the process builder. So I checked Flow and it was still not available.

How can I change a custom field value based on a specific criteria when a record is created or edited???

Can I do this without using APEX code?


VinayVinay (Salesforce Developers) 
Hi Dave,

Unfortunately,  you cannot do without using apex code or trigger.

You are not allowed to write trigger on PriceBookEntryObject but you can try using apex class.

You need to think of using product2 fields or some alternate approach which can indirectly update pricebookentry field.

Below is the sample snippet to update pricebook entry when product is updated
trigger PricebookEntry on Product2 (after insert, after update) {
    Set<ID> prodIdSet = Trigger.newMap.keySet();
    Pricebook2 pb = [select ID from Pricebook2 where IsStandard = TRUE and IsActive = TRUE];

    List<PricebookEntry> pbeList = new List<PricebookEntry>();

    if(trigger.isinsert) {
        for (Product2 p : {
            pbeList.add( new PricebookEntry( Pricebook2Id = pb.ID, Product2Id=p.ID, UnitPrice = p.Price__c, IsActive = p.IsActive, UseStandardPrice = FALSE));
        insert pbeList;
    if(trigger.isupdate) {
        List<PricebookEntry> existPBEList = [SELECT Id, UnitPrice, Product2Id FROM PricebookEntry WHERE Product2ID in : prodIdSet];
        if(existPBEList != null && !existPBEList.isEmpty()) {
            Map<Id, PriceBookEntry> prodPBEMap = new Map<Id, PriceBookEntry>();
            for(PricebookEntry pbe: existPBEList) {
                prodPBEMap.put(pbe.Product2Id, pbe);
            for (Product2 p : {
                PriceBookEntry tempPBE = prodPBEMap.get(p.Id);
                if (tempPBE != null) {
            update prodPBEMap.values();

References: (Idea link)

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Vinay Kumar