Salesforce 创建QuoteLineItems时缺少PriceBookEntry必填字段
我是CPQ的新手,一直在尝试创建报价行项目,但没有成功Salesforce 创建QuoteLineItems时缺少PriceBookEntry必填字段,salesforce,apex,Salesforce,Apex,我是CPQ的新手,一直在尝试创建报价行项目,但没有成功 Opportunity OpportunityOne = [SELECT Id, PriceBook2Id FROM Opportunity WHERE Id='0067F000008qOJzQAM' LIMIT 1]; Quote QuoteOne = [SELECT Id FROM Quote WHERE Name =:'TestQuote' LIMIT 1];
Opportunity OpportunityOne = [SELECT Id, PriceBook2Id FROM Opportunity WHERE
Id='0067F000008qOJzQAM' LIMIT 1];
Quote QuoteOne = [SELECT Id FROM Quote WHERE Name =:'TestQuote' LIMIT 1];
Product2 Product = [SELECT Id FROM Product2 WHERE Id
=: '01t7F0000032Y89QAE' LIMIT 1];
System.debug('Opportunity: '+OpportunityOne);
System.debug('Quote:'+QuoteOne);
System.debug('Product2:'+Product);
QuoteLineItem QuoteLineItemOne = new QuoteLineItem();
QuoteLineItemOne.QuoteId = QuoteOne.Id;
QuoteLineItemOne.Quantity = 100;
QuoteLineItemOne.UnitPrice = 2000;
QuoteLineItemOne.Product2Id = Product.Id;
insert QuoteLineItemOne;
为什么它总是说价格帐簿条目丢失了。真烦人。插入失败,我看不到需要价目表输入字段的对象
请帮我解决这个问题。您需要将apex API版本回滚到版本38或更早的版本,以便以这种方式创建报价行(使用
product2Id
字段)。从第39版开始,您需要填充pricebookentryId
字段,并将product2Id
保留为空。要获取pricebookEntryId
,您只需要额外的查询,例如
PriceBookEntry pbe = [SELECT id FROM PricebookEntry
WHERE Product2Id =: Product.id AND Pricebook2Id =: OpportunityOne.pricebook2Id LIMIT 1];
然后只需在quotelineitem
上设置pricebookentryId
字段,而不是product2Id