Activity Forums Salesforce® Discussions How to write trigger on PriceBookEntry in Salesforce?

  • Piyush

    Member
    January 10, 2018 at 8:22 am

    We have a requirement to write trigger on PriceBookEntry. Whenever a new pricebook entry is created or update we have to fire a event to generate a custom report.
    As per Salesforce standard they not allow to write trigger on PriceBookEntryObject. Then what is the work around to achieved that.
    Any help will really appreciable.

  • Manpreet

    Member
    January 16, 2018 at 3:00 pm

    Hi piyush,
    Instead of trigger I used a apex class and scheduled to run it every 15 mins. That is not a big load on Salesforce. The apex class holds one important query – It gets all the PriceBookEntry which are “modified in the last 15 minutes”. And then we perform all the updates required based on that.
    You can use field SystemModStamp. So that includes both “Inserts and Updates” done on PriceBookEntry

    List PBEUpdated15mins = [SELECT Id,Pricebook2Id
    FROM PriceBookEntry WHERE
    SystemModStamp >:Datetime.now().addMinutes(-15)];
    If you want the scheduler to run only on Insert of Pricebookentry, then instead of SystemModStamp, use CreatedDate in the query WHERE condition.

    List PBEUpdated15mins = [SELECT Id,Pricebook2Id
    FROM PriceBookEntry WHERE
    CreatedDate >:Datetime.now().addMinutes(-15)];
    Similarly if you want only Updates, you can replace with LastModifiedDate.

    Thanks

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos