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
ApexDevApexDev 

Apex class to fill the lookup field

Hi Everyone! :)   On PricebookEntry object, I have a 2 lookup fields: 
 - Pricebook2Id (standard field filled by Integration)
 - Price_Book_2__c (custom field needed for Related list) 
 
I want to fill the Price_Book_2__c using the value in Pricebook2Id.  I am trying to write the class, it will be my first apex class, I invoke it using Flow and later Process Builder, but the field is still empty 
 


public class PriceBookField
{
    @InvocableMethod
    public static void PriceBookField(List<Id> PBIds){
        List<PricebookEntry> XYZ = [Select Id, Pricebook2Id, Price_Book_2__c from PricebookEntry where ID in: PBIds];
        for(PricebookEntry PB : XYZ){
            PB.Price_Book_2__c = PB.Pricebook2Id;
        }
        update XYZ;
    } 
}