Skip to main content
durga prasad ha fatto una domanda in #Apex
hi,

 i am new to salesforce i have small doubt we have run time information store using trigger.new holding all newly created redords.

my doubt is we have all new record then why we are writing soql queries in triggers
2 risposte
  1. 14 set 2015, 16:47
    In following case we need to execute Query inside trigger

    1) Some time we need to fatch the related object record in trigger in that case we also need to execute Soql

    2) We need to fatch the reference record value (Lookup) . For example Account detail in Contact Trigger.

    3) If Trigger is on After Event in that case also we need query the record if we need to update the same record.

    Trigger Best Practices

    1) One Trigger Per Object

    2) Logic-less Triggers

    3) Context-Specific Handler Methods

    4) Bulkify your Code

    5) Avoid SOQL Queries or DML statements inside FOR Loops

    6) Using Collections, Streamlining Queries, and Efficient For Loops

    7) Querying Large Data Sets

    NOTE:- Trigger.new will give you same object record only

    Please check below post for more info

    http://amitsalesforce.blogspot.com/2015/06/trigger-best-practices-sample-trigger.html

    Please let us know if this will help you

    Thanks

    Amit Chaudhary
0/9000