You need to sign in to do that
Don't have an account?
Trigger for creating a pricebook entry
HI,
When a Product is created or edited, create a Price Book Entry in the Standard Price Book with the Advertised Price from the input record.
For this i wrote the following Trigger
trigger TrgPricebookEntry on Product2 (before insert,before update) {
list<Product2> lstproduct=new list<Product2>();
list<PricebookEntry> lstPbe=new list<PricebookEntry>();
PricebookEntry PB;
if(trigger.isinsert){
for(Product2 objProduct:trigger.new)
{
PB=new PricebookEntry();
PB.UnitPrice=objProduct.Advertised_Price__c;
PB.UseStandardPrice=true;
PB.IsActive=true;
PB.Pricebook2Id=objProduct.id;
lstPbe.add(PB);
}
insert lstPbe;
}
if(trigger.isUpdate){
for(Product2 objProduct:trigger.new)
{
PB=new PricebookEntry();
PB.UnitPrice=objProduct.Advertised_Price__c;
PB.UseStandardPrice=true;
PB.IsActive=true;
PB.Pricebook2Id=objProduct.id;
lstPbe.add(PB);
}
insert lstPbe;
}
}
But it is not working.Any Help regarding this is highly appreciated.
Regards,
Abhi
This one had me stumped for ages
Run this using Execute Anonymous to see it working
This should help you.
Hi,
Thanks Gill.Its working in Execute anonymous.But my question is how can we use it in the trigger?
Regards,
Abhi
I hope this helps you - remove the UseStandardPrice = true