2

I want to use standard price for the Pricebook entry.

  PricebookEntry pbe = new PricebookEntry(Pricebook2Id='01sN00000002OTsIAM',
        IsActive=true, 
        Product2Id='01tN0000004JGeuIAG', 
        UseStandardPrice=true
        );
    insert pbe;

I get this error.

REQUIRED_FIELD_MISSING, Required fields are missing: [UnitPrice]: [UnitPrice]

So, I changed to mention the List Price (which is the unitPrice). I still get the error!

PricebookEntry pbe = new PricebookEntry(
    Pricebook2Id='01sN00000002OTsIAM',
    IsActive=true, 
    Product2Id='01tN0000004JGeuIAG', 
    UseStandardPrice=true,
    UnitPrice = 0.70
    );

insert pbe;

I get the following error

Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception

UPDATE

I read that UseStandardPrice==true cannot be set. It has to be false. help.salesforce.com/articleView?id=000193277&type=1

Setting it to False actually inserts the record. But I want it to be set to true.

4
  • Do pricebookentry already has value for the pricebook2id and product2id combination? Commented Aug 7, 2017 at 7:25
  • No! I did query for that - 0 results (select id from pricebookentry where Pricebook2Id='01sN00000002OTsIAM' AND Product2Id='01tN0000004JGeuIAG')
    – sfdcFanBoy
    Commented Aug 7, 2017 at 7:33
  • Is the Pricebook2Id you are using is Standard Price Book Id? Commented Aug 7, 2017 at 7:57
  • No. It is Custom pricebook. Trying to add the product to this custom pricebook
    – sfdcFanBoy
    Commented Aug 7, 2017 at 8:11

1 Answer 1

1

I have figured out that we cannot set UseStandardPrice=true on insert. On insert it has to be set to False first, along with mentioning UnitPrice. Then later do an additional update to set the UseStandardPrice=true.

PricebookEntry pbe = new PricebookEntry(
    Pricebook2Id='01sN00000002OTsIAM',
    IsActive=true, 
    Product2Id='01tN0000004JGeuIAG', 
    UseStandardPrice=false,
    UnitPrice = 0.70
    );

insert pbe;

pbe.UseStandardPrice = true;
update pbe;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .