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 › How can i call relationship object fields in Salesforce trigger?

    Tagged: Account, Relationship Object, Salesforce Apex, Salesforce Fields, Salesforce SOQL, Salesforce Trigger

    • Salesforce® Discussions

      How can i call relationship object fields in Salesforce trigger?

      Posted by Naman on April 30, 2016 at 5:43 PM

      How can i call relationship object fields in trigger?

      William replied 7 years, 1 month ago 4 Members · 3 Replies
      • Account
      • Relationship Object
      • Salesforce Apex
      • Salesforce Fields
      • Salesforce SOQL
      • Salesforce Trigger
    • 3 Replies
    • Surbhi

      Member
      May 30, 2016 at 5:28 AM

      Hi Naman,

      Here is the solution for what I understand from your question:

      Suppose you have a trigger on Contact and you want to access Account fields.

      trigger afterInsertContact on Contact (after insert){
      for(Contact conObj : trigger.new){
      system.debug(conObj.AccountId);
      }
      }

      For standard relationships, you can simply use the . (dot) notation and refer to the fields.
      However for a custom relationship, you need to use __c and __r.

      Thanks

    • Avnish Yadav

      Member
      September 30, 2018 at 1:39 AM

      You should be specifying more details, however at a high level this is how you do it

      Supposing your trigger is on Contact and you want to access Account fields, this is how you do it.

      trigger triggerContact on Contact (after insert){
      for(Contact cont : trigger.new){
      system.debug(cont.AccountId);
      }
      }

      The bold text is where I am fetching the account id for each contact in trigger. Similarly you can refer other fields.

      NOTE: for standard relationships, you simply use the . (dot) notation and refer the fields.
      However for a custom relationship, you need to use __c and __r

      example: custom object patient__c is related to Account standard object (relationship field : Account__c).
      patient__r.Account__c - this will give me account id for a patient record.

      Hope this helps!

    • William

      Member
      November 28, 2018 at 4:56 AM

      We have two object account and contact. In this scenario, you have a contact object which has a lookup relationship to account. When processing the contact records in your trigger, you want to access some fields on the account via the relationship. Your trigger might look something like this:

      trigger parent2child on Account (after update) {
          list<id>ids = new list<id>();
          list<contact>conlist = new list<contact>();
          for(account a:trigger.new){
              ids.add(a.id);
              list<contact>con =[select id,phone,account.phone from contact where accountid in:ids];
              for(contact c:con) {
                  c.Phone=c.account.phone;
                  conlist.add(c);
              }
              update conlist;
          }
      }
      • This reply was modified 7 years, 1 month ago by  William.

    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

    Difference Between Palace on Wheels & Maharajas Express Train

    Blog in Others

    When it comes to luxury train travel in India, two names stand out: Palace on Wheels and Maharajas Express. Both offer an opulent experience, but they differ in several aspects, including…

    Orient Rail Jul 30, 2025
    211  Views
    Salesforce Integration For Business Growth

    Why Salesforce Integration Can Be Your Best Bet for Business Growth

    Blog in Salesforce integration

    Welcome to the age of the Customer. The only riddle that matters here is—how to connect better with them, carve meaningful relationships, address their problems…

    Business Operations, Business Success, Data Visibility, Salesforce Integration, Salesforce Integration Partners
    Rahul Sep 25, 2017
    3,764  Views
    salesforce certifications

    The Perks of Getting a Salesforce Certification

    Blog in Salesforce Certifications

    Certifications are the way to go these days if one is looking to upskill and grow their career. Degrees are great, but a course certification…

    career, Certification in Salesforce, Certifications, Certified Employer, Course Certification
    Swathi Aug 29, 2022
    3,230  Views

    Popular Salesforce Videos

    Salesforce Integration Using Oracle SOA Suite

    Salesforce Integration Using Oracle SOA Suite

    Video in Salesforce Integration

    In this video, Bristlecone gives an introduction to Oracle Cloud Adapter for Salesforce.com.  Afterwards, he goes into detail about how to integrate Salesforce.com using Oracle…

    Salesforce Training, Salesforce Tutorial, Salesforce Integration, salesforce, #integration
    Rahul kapoor Sep 7, 2022
    1,950  Views
    What is Billing - Salesforce Revenue Cloud

    What is Billing - Salesforce Revenue Cloud

    Video in Salesforce Cloud Platform

    How can you transform your billing system for subscription and usage models? By dropping your legacy systems and streamlining your processes. In this video, learn…

    Salesforce Training, Salesforce Video, Customers, Salesforce Learning, Subscription
    Jogender Jan 27, 2021
    2,230  Views
    Salesforce Lightning User Tips & Tricks Spring 2021

    Salesforce Lightning User Tips & Tricks Spring 2021

    Video in Lightning

    This session is one of our most popular Webinars. It includes tips and tricks that any Salesforce user will find helpful. Learn Salesforce shortcuts that…

    Salesforce Training, Salesforce Lightning, Salesforce Classic, Salesforce Webinar, Salesforce Video
    Abhishek Sep 8, 2021
    4,491  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.