You need to sign in to do that
Don't have an account?
kcnmahesh
How to get current record values when we are working with triggers
I created one trigger on an object.
The trigger executes when we do any operations on an object.
I need to get the current record values.
How can i get the current record values or ID.....?
Hi
You can get the current record by Trigger.new context variable.
For Example:
Trigger test on Account (after insert) {
for (Account a : Trigger.new) {
// Iterate over each sObject records that were inserted
}
// This single query finds every contact that is associated with any of the
// triggering accounts. Note that although Trigger.new is a collection of
// records, when used as a bind variable in a SOQL query, Apex automatically
// transforms the list of records into a list of corresponding Ids.
Contact[] cons = [SELECT LastName FROM Contact
WHERE AccountId IN :Trigger.new];
}
You can get the current record Id by below:
Id id = Trigger,new[].Id;
If this helps you. Mark it as resolved
Cheers
Sanj