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

  • 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

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos