Free Salesforce Developers Tutorials >

Chapter - 9 Apex Triggers >

Trigger.newMap | Context Variables in APEX Triggers

Trigger.newMap | Context Variables in APEX Triggers

What You’ll Learn

S2 Labs


This variable returns a map of ids to the new versions of sObject records.


This map is only available in before update, after insert, after update and after undelete triggers.

trigger ApexTrigger on Account(before update) {
    // Only available in beforeUpdate, afterUpdate, afterInsert, afterUndelete Triggers 
    Map < Id, Account > nMap = new Map < Id, Account > ();
    nMap = Trigger.newMap;
    List < Contact > cList = [SELECT LastName FROM Contact WHERE AccountId IN: nMap.keySet()];
    for (Contact c: cList) {
        Account a = nMap.get(c.AccountId);
        c.MailingCity = a.BillingState;
    update cList;

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *