You need to sign in to do that
Don't have an account?
shan876
Pricebook..Standard Price???
Hi all:
I am using an Integration Tool to upload data into the products2 and pricebookEntry table... Now, I can load data into the product2 table no issues there. But when I try to load the pricebookentry to link back to product2Is and pricebook2Id.. the issue I have having is "[SFDC] No standard price defined for this product [SFDC] STANDARD_PRICE_NOT_DEFINED"
Ok Now I know that standard price is the default unit price if you go through the excel connector in a Product table...
But how do you fill it through an API when it is not part of the product2 table???
Any help ... Please Advise...
Thanks
Shan
I am using an Integration Tool to upload data into the products2 and pricebookEntry table... Now, I can load data into the product2 table no issues there. But when I try to load the pricebookentry to link back to product2Is and pricebook2Id.. the issue I have having is "[SFDC] No standard price defined for this product [SFDC] STANDARD_PRICE_NOT_DEFINED"
Ok Now I know that standard price is the default unit price if you go through the excel connector in a Product table...
But how do you fill it through an API when it is not part of the product2 table???
Any help ... Please Advise...
Thanks
Shan
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;
}
}
Hope this helps,
James
hi Wilbur:
Thank you for the response... This trigger is this a custom s-control?? or an app you wrote...
It looks good but How do I utilize it and where would I place it..
Because I am uploading the products from an integration tool but ready to write a VB app to do so?
Please advise
thanks
Shan
You may want to set the Unit Price to something other than 0.00 in the code.
To set the standard price for all your products you can manually insert a price for each product in salesforce or write an s-control that sets the price and then run it from a custom tab or button. The code will look something like this:
Product2[] a = [select id from Product2];
sObject s = [select ID from Pricebook2 where IsStandard = TRUE];
for( Product2 b : a ) {
PricebookEntry z = new PricebookEntry(Pricebook2Id=s.ID, Product2Id=b.ID, UnitPrice=0.00, IsActive=TRUE, UseStandardPrice=FALSE);
insert z;
}
but of course your s-control will not use APEX code but probably AJAX code with salesforce classes.
James
On second thought if you are uploading the products from somewhere else, upon creation the trigger will create a standard price for each of your products. No need to write an s-control that does this.
James
Hi :
So I created the Trigger and package in my test environment and now I am trying to upload it and I get the following error:
No testMethods found in the selected Apex code for the package
What does that mean??
you have to create a test class to test the code in the trigger. It's not hard, just read the documentation on unit testing.
James
so do I create this class within the same trigger that I created or a different trigger??
then paste my code in and save.
When you create the package include this class.
public class myClass {
static testMethod void testInsertLine() {
Product2 p = new product2(name='x',isactive=TRUE);
insert p;
System.assertEquals(0.00, [select UnitPrice from PricebookEntry
where product2id = :p.id].UnitPrice);
}
}
where product2id = .id].UnitPrice);
Also, thank you so much for helping me out.. I do really appreciate this...
hi:
So I deployed the trigger and class and all through the eclipse tool... Works nicely
Now, I am using the intergration tool to upload my products into salesforce.com through Bluewolf ESI Tool
I keep getting an email and errors stating:
Apex script unhandled trigger exception by user/organization: 00550000000lxVc/00D500000006sSF
AutoPopulatePricebookEntry: execution of AfterInsert
caused by: System.Exception: Too many DML statements: 21
Trigger.AutoPopulatePricebookEntry: line 9, column 11
James
I emailed support and they told me to:
It looks like you need to pull your insert statement out of that loop- instead of doing an insert for each record processed, you can cache them all up in an array-type structure and then insert them all at once
I have not tried it ... still trying to figure out a better way...
I'm trying execute you test and did not work, show me message fail below:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoPopulatePricebookEntry: execution of AfterInsert
caused by: System.QueryException: List has no rows for assignment to SObject
Trigger.AutoPopulatePricebookEntry: line 2, column 1: []
Regard,
Paulo
https://help.salesforce.com/servlet/servlet.FileDownload?file=01530000001OdbFAAS (https://help.salesforce.com/servlet/servlet.FileDownload?file=01530000001OdbFAAS" target="_blank)
you have to add them to the standard pricebook first, and then a standard price exists so you can add them to a custom pricebook.