Activity Forums Salesforce® Discussions Why can there only be one trigger for each Salesforce Object?

  • suniti

    Member
    June 28, 2018 at 12:05 pm

    You can have n number of triggers on single objects, but best practice is to have all trigger event operations into the singe trigger with the if conditions.

  • Avnish Yadav

    Member
    September 10, 2018 at 6:38 am

    Hi Prachi,

    You can write as many triggers per Object, but the allowed limit is 3,000,000 characters for the entire triggers and apex classess for a dev org, and the best practice is to have all trigger event operations into the singe trigger with the if conditions.

    Thanks.

  • Parul

    Member
    September 10, 2018 at 6:55 am

    Hi Prachi,

    Triggers operate in collections of 200 records.

    • If you update one record in a DML statement, the trigger will have that one record in its collection.
    • If you update 100 records in a DML statement, the trigger will have 100 records in its collection.
    • If you update 200 records in a DML statement, the trigger will have 200 records in its collection.
    • If you update 1000 records in a DML statement, the platform will chunk the 1000 records into groups of 200. Your trigger will run 5 times, with 200 records in each invocation.

    Triggers must be written to handle records in collections of 200. Your use case currently might only be that one record will be updated and one HTTP Request will be made to an external system but there are plenty of ways that more than one Account can be updated at a time and your code needs to handle those scenarios gracefully.

     

    Thanks.

  • shariq

    Member
    September 15, 2018 at 10:45 am

    Hi,

    There is no limit to write triggers on single sobjects, but best practice is to write one trigger for one sobject and make your functionality in that trigger. Use Context variables and comment the code for more clarity.

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs