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
asish1989asish1989 

problem in price book entry

Hi 

 I am facing problem when we add product in a custom page.I could not
able to know how to use standard price which is given in
salesforce.Even I can not know

 which object contains this field. I tried by making a custom field
Price in product.But stil I faced   problem when I am assigning
product to Quote Line Items object

 because     there is a required field in QuoteLineItems that is
PricebookEntry Id.I do not know how to make required field to
Unrequired in a standard  Object.

 If   you have  any   solution please help me.

error name is Standard Price is not defined for this product...

 

 

 

with Regards

asish

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

tahnks for replying . I got solution.I have set a trigger before entry in product2.its working .No error is found.Thanks Salesforce

 

the Apex code which I have set in trigger is

 

trigger AutoPopulatePricebookEntry on Product2 (after insert) {

sObject s = [select ID from Pricebook2 where IsStandard = TRUE];

for (Product2 newProduct: Trigger.new) {

PricebookEntry z = new PricebookEntry(Pricebook2Id=s.ID,Product2Id=newProduct.ID, UnitPrice=0.00, IsActive=TRUE, UseStandardPrice=FALSE);
insert z;

}

}

 

 

Thanks again Salesforce

 

All Answers

Ritesh AswaneyRitesh Aswaney

It might be useful just to understand how Products and Pricebooks are structured in Salesforce.

 

Products are related to PriceBooks via PriceBookEntries (many - many junction objects)

Pricebooks can either be standard or custom.

 

Opportunity Line Items and Quote Line Items refer to the PriceBookEntryId rather than the ProductId

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_pricebookentry.htm

 

The UseStandardPrice field on the PriceBookEntry dictates whether the standard price specified in the pricebook is to be used or a custom one may be specified.

asish1989asish1989

Thans for replying .I did what You suggested but stil I am fasing same problem.I know that Pricebook2 and Product2 are related in

 

 a many to many relationship.junction Object is PricebookEntry. I have written the code like this

 

   public PricebookEntry pbentry{get;set;}
    public Pricebook2 pb{get;set;}
     public Product2 product{get;set;}
    public QuoteLineItem qutlineitem{get;set;}
  

  
   public PageReference tosaveProduct() {
  
   insert product;
 
   pb.Name='Standard';
 
   insert pb;
   pbentry.Product2Id=product.Id;
   pbentry.Pricebook2Id=pb.Id;
  // pbentry.UnitPrice=0.00;
   pbentry.UseStandardPrice=true;
   
   insert pbentry;
   qutlineitem.PricebookEntryId=pbentry.Id;
   insert qutlineitem;
 
   return null;
   }

 

Error Name is Stanarad Price Is not defined for this product....

 

yvk431yvk431

Is this a test method ?

 

If so try to use an existing standard PriceBook which is active rather than creating a new one.

Check the below post

 

http://boards.developerforce.com/t5/Apex-Code-Development/unit-test-error-standard-price-not-defined/td-p/263455

 

 

 

--yvk

asish1989asish1989

tahnks for replying . I got solution.I have set a trigger before entry in product2.its working .No error is found.Thanks Salesforce

 

the Apex code which I have set in trigger is

 

trigger AutoPopulatePricebookEntry on Product2 (after insert) {

sObject s = [select ID from Pricebook2 where IsStandard = TRUE];

for (Product2 newProduct: Trigger.new) {

PricebookEntry z = new PricebookEntry(Pricebook2Id=s.ID,Product2Id=newProduct.ID, UnitPrice=0.00, IsActive=TRUE, UseStandardPrice=FALSE);
insert z;

}

}

 

 

Thanks again Salesforce

 

This was selected as the best answer
Cloud_BKCloud_BK

Asish:

 

I am working on a similar problem,

 

i am trying to update a custom object with product prices.

 

In your trigger code above, what is the sObject?  is that your custom object or is that related to the Product?

 

Thanks,

 

Brian

asish1989asish1989

Its a standard object Product2.