title: Salesforce - insert record to PricebookEntry table for Standard pricebook
body: <p>I have been trying to insert new records to PricebookEntry table for standard pricebook. I need to do this since I need to insert record for custom pricebook. However, it keep getting error. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>Pricebook2 standardpricebook = [select id from Pricebook2 where isStandard=true];
  System.debug(standardpricebook.id);
  PricebookEntry standardprice = new PricebookEntry(Pricebook2Id = standardpricebook.id, Product2Id = Product2Id[i], Name__c=Name[i], UnitPrice = 0.00, IsActive = true, UseStandardPrice=false);
  insert standardprice;
  </code></pre>
  
  <p>This code failed with this error:</p>
  
  <p>Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, This price definition already exists in this price book: []</p>
  
  <p>After few hour of researching, I found this website, <a href="http://www.fishofprey.com/2012/03/salesforce-obscure-field-integrity.html" rel="nofollow noreferrer">http://www.fishofprey.com/2012/03/salesforce-obscure-field-integrity.html</a></p>
  
  <p>which indicate I have to set the UseStandardPrice to true. If I do this, it get this error:</p>
  
  <p>Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []</p>
  
  <p>According to the website above, I can't set the UnitPrice when UseStandardPrice set to true. Is there anyway to insert the record with standard pricebook?</p>
  
  <p>Thank you</p>