You need to sign in to do that
Don't have an account?
john98755
soql with triggers
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
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
Inside trigger if any refrence field value if you want then you need to query as trigger.new only contain the reference id not any other field value .
Like in contact trigger you will get only account id not any other field value to get other field values you need to query from account with id .
incase of after event you need to query as trigger .new is always readonly on after event .In that case also you need to query .
Check the below link for some concepts of trigger .
http://manojjena20.blogspot.in/2013/03/manojs-trigger-blog.html
Let me know if it helps
Thanks
Manoj
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