Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Marketplace
    • Advertise With Us
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › What is the use of oldMap and newMap context variables in Salesforce Triggers?

    Tagged: Account ID, Account Record, Context Variables, DML Operations, Salesforce Records, Salesforce Triggers, sObject List Type, Trigger New, Trigger NewMap, Trigger Old, Trigger OldMap, Update, Variables and Methods

    • Salesforce® Discussions

      What is the use of oldMap and newMap context variables in Salesforce Triggers?

      Posted by Anurag algoworks on July 30, 2018 at 11:22 AM

      What is the use of oldMap and newMap context variables in triggers and how are they different from 'old' and 'new' context variables?

      Parul replied 7 years, 4 months ago 4 Members · 4 Replies
      • Account ID
      • Account Record
      • Context Variables
      • DML Operations
      • Salesforce Records
      • Salesforce Triggers
      • sObject List Type
      • Trigger New
      • Trigger NewMap
      • Trigger Old
      • Trigger OldMap
      • Update
      • Variables and Methods
    • 4 Replies
    • Anjali

      Member
      July 30, 2018 at 1:11 PM

      Hello Anurag

      Trigger.old: Returns a list of the old versions of the sObject records. Note that this sObject list is only available in update and delete triggers. Trigger.new will have current details of the record getting inserted or updated, where as trigger.old will have the existing details for a record before it is updated or deleted.

      Trigger.OldMap: A map of IDs to the old versions of the sObject records. Note that this map is only available in update and delete triggers.

      Trigger.new: Trigger.new is a list of sobjects. If we are talking about a DML operation on account, then trigger.new is simply a list of accounts. Similarly when used in contact trigger, trigger.new becomes a list of contacts.

      Trigger.newMap: Trigger.newMap is a map with key as ID of the record and value as the record itself. Just like the above explanation, in case of accounts when we say trigger.newMap we are talking about a map of key-value pairs where the key is the account ID and the value is the account record itself.

    • Parul

      Member
      September 18, 2018 at 7:36 AM

      Trigger.OldMap: A map of IDs to the old versions of the sObject records. Note that this map is only available in update and delete triggers.

      Trigger.newMap: Trigger.newMap is a map with key as ID of the record and value as the record itself. Just like the above explanation, in case of accounts when we say trigger.newMap we are talking about a map of key-value pairs where the key is the account ID and the value is the account record itself.

      A map of IDs to the new versions of the sObject records.Note that this map is only available in before update, after insert, and after update triggers.
      oldMap
      A map of IDs to the old versions of the sObject records.Note that this map is only available in update and delete triggers.

       

      Thanks

    • shariq

      Member
      September 21, 2018 at 12:25 AM

      Hi,

      Trigger.new return the ordered list whereas trigger.newmap returns a map which is unordered

      In otherways

      Trigger.new
      Returns a list of the new versions of the sObject records. Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.
      Trigger.NewMap
      A map of IDs to the new versions of the sObject records, this map is only available in before update, after insert, and after update triggers.

      Hope this helps.

    • Parul

      Member
      September 21, 2018 at 4:41 AM

      Hi , Difference in oldMap and newMap

      //Trigger.new: Contains all new Data
      //Trigger.Old: Contains all old Data (before change)
      //Trigger.newMap: Map contains new Data (Key: Id)
      //Trigger.oldMap: Map contains old Data (Key: Id)
      for(Opportunity opp:Trigger.New){
      if(opp.Stage != Trigger.oldMap.get(opp.Id).Stage){
      //Your logic
      }
      }
      //Same way you can use Trigger.newMap

      I hope this will helpfull to you.

      Thanks

       

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    application solution

    Popular Salesforce Blogs

    Workflow Rules

    Workflow Rules in Salesforce - Get Started

    Blog in Salesforce

    What is a Workflow Rule? Workflow rule can be defined as an automated mechanism in Salesforce by which we can perform 4 types of actions…

    Automated Mechanism, Automated Work, Business Automated, Business Users, email alert
    Romil Singh Dec 9, 2021
    3,286  Views
    Inserting Records in Account or (any other sObject) Through Postman in salesforce

    Inserting Records in Account or (any other sObject) Through Postman in Salesforce

    Blog in Salesforce Apex

    We are using postman from API testing and request management to hit API by get or post and received data in the form of JSON…

    connected app, oAuth2, Postman, Rest API, Salesforce
    Nitin Aug 29, 2017
    30,652  Views
    Amazon Lex API implementation with Salesforce for ChatBot

    Amazon Lex API implementation with Salesforce for ChatBot

    Blog in Coding and Scripting, Lightning

    Lex is Amazon’s service for building conversational interfaces into any application using voice and text. It is powered by the same algorithms used by Amazon…

    API Implementation, Client-Side Controller, Implement Salesforce Lightning, Lex ChatBot, Salesforce Chatbot
    Neha Mar 22, 2018
    13,556  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.