+ Start a Discussion
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12 

How to send Email Notification?

HI,

How to Send the Email notification. when the product pricebook price value changed?

Thanks,
PratikPratik (Salesforce Developers) 
Hi Sundhar,

You can write a trigger on Pricebookentry. 
Here are the helful links:
http://salesforce.stackexchange.com/questions/38947/sending-email-notification-using-trigger
http://salesforce.stackexchange.com/questions/64886/get-pricebookentry-standardprice-value-into-soql-query
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008ymcIAA

Thanks,
Pratik
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi pratik,

I tried to send Email notification , when the pricebookentry price changed include standard price also. But i got compile error

Please refer the following code. what my mistake
trigger
=================
trigger PricebookEntry on Pricebook2(before insert, before update){
PricebookTriggerHandler handler = new PricebookTriggerHandler();

     if(trigger.isBefore && trigger.IsInsert){
       handler.OnBeforeInsert(trigger.newmap, Trigger.OldMap);
    } 
      
    if(trigger.isBefore && trigger.IsUpdate){
      handler.OnBeforeUpdate(trigger.newmap, Trigger.OldMap);
    } 
    
}

Trigger Controller
========================
Public class PricebookTriggerHandler{

    Public void OnBeforeInsert(map<id,Pricebook2> PrdNewMap,map<id,Pricebook2> PrdOldMap){
    
    }
    Public void OnBeforeUpdate(map<id,Pricebook2> PrdNewMap,map<id,Pricebook2> PrdOldMap){
        EmailNotification(PrdNewMap,PrdOldMap);
    }

   Public void EmailNotification(map<id,Pricebook2> PrdNewMap,map<id,Pricebook2> PrdOldMap){
    Set<Id> PriceId = new Set<Id>();
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    
    for(pricebook2 price:PrdNewMap.values()){
        
     pricebookEntry Stdprice = [SELECT Id, Unitprice, UseStandardPrice FROM PricebookEntry WHERE Id = :priceId];

      Messaging.reserveSingleEmailCapacity(1);
       
       Messaging.SingleEmailMessage PriceNotificationmail = new Messaging.SingleEmailMessage(); 
     //  PriceNotificationmail.setToAddresses('sundhar.mks@gmail.com');
       PriceNotificationmail.setReplyTo('Sundhar.mks@gmail.com');
       PriceNotificationmail.setSenderDisplayName('Salesforce Support'); 
       
       
       String oldUnitprice = PrdOldMap.get(price.id).Unitprice;   ==>  Compile Error: Invalid field Unitprice for SObject Pricebook2 at line 26                                                                                                               column 54

        if (price.Unitprice != oldUnitprice) {
            PriceNotificationmail.setSubject(' Pricebook price updation : ' + 'Changed to ' + price.Unitprice + '. Pricebook Id:' + price.Id);
           // CaseNotificationmail.setPlainTextBody('Your pricebook : ' + ' has been updated.'+'To view your pricebook <a href=<a target="_blank" href="https://cs16.salesforce.com/'+price.Id'">https://cs16.salesforce.com/'+price.Id);</a>
  
        } 
     // Messaging.sendEmail(new Messaging.SingleEmailMessage[] { PriceNotificationmail});
      mails.add(PriceNotificationmail);
      }
     Messaging.sendEmail(mails);
    }

}