• Leyden44
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi everybody,

 

I have a trigger, that adds prices in all available currencies to a new inserted product in the standard price book.

What I need now, is to add that prices to a custom pricebook with that same prices. 

 

My current Code is:

 

 

trigger Product_AfterInsert_PriceBookEntry on Product2 (after insert) {


Map<ID,Product2> InsertedProducts = trigger.NewMap;


PriceBookEntry[] ExistingPBE = [SELECT ID
FROM PriceBookEntry
WHERE Product2ID IN :insertedproducts.keySet()];

Delete ExistingPBE;

CurrencyType[] ActiveCurrencies = [SELECT c.IsoCode, c.ConversionRate
FROM CurrencyType c
WHERE c.IsActive = True];

ID StdPriceBookID = [SELECT p.Id From Pricebook2 p
WHERE p.IsStandard = true][0].ID;

PriceBookEntry[] NewPBE = new PriceBookEntry[]{};

for(Product2 p: trigger.new){

if (p.AutoActivate__c) {

for(CurrencyType curcode: ActiveCurrencies){
NewPBE.add( new PriceBookEntry(Product2ID=p.ID,
PriceBook2ID=StdPriceBookID,
CurrencyIsoCode=curCode.IsoCode,
IsActive=True,
UnitPrice=p.SourceBasePrice__c * curcode.ConversionRate,
UseStandardPrice=False) );





if (!NewPBE.isEmpty()) { 
Insert NewPBE;
}

}

 

Any help highly appreciated.

Thanks

 

Hello

 

I would like to know if it's possible to notify a user when there are field record changes. For example:case status was changed, priority was changed etc...

Structure of the email should be like this:

 

  • Who changed (I assume it can be "Last Modified By")
  • What was changed (Field and new value)
  • Link to case

I know that is possible to create a workflow and email for every field change, but i'm wondering if there's an elegant way (as I have around 10 fields)

 

Thanks

 

Itay