Toggle Side Panel

  • Blogs
  • 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
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Blogs
    • 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
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › How to change the account owner in contact by a apex trigger?

    Tagged: Person Account, Salesforce Apex, Salesforce Trigger

    • Salesforce® Discussions

      How to change the account owner in contact by a apex trigger?

      Posted by Mohit on July 20, 2016 at 2:34 PM

      Hi all,

      How to change the account owner in contact by a apex trigger?

      please give suggestion

      Prakhar replied 10 years, 3 months ago 2 Members · 1 Reply
      • Person Account
      • Salesforce Apex
      • Salesforce Trigger
    • 1 Reply
    • Prakhar

      Member
      July 20, 2016 at 3:39 PM

      Hii Mohit,

      Yes you can update the account owner, when firing trigger on the contact. Please take help from below code and modify it according to your requirement.

      trigger updateAccountOwner on Contact (before update) {

      Set<Id> relatedAccountId = new Set<Id>();
      List<Account> updatedList = new List<Account>();
      for(Contact con: trigger.new){
      if(con.AccountId != Null){
      relatedAccountId.add(con.AccountId);
      }
      }

      for(Account acc: [Select Id, Name ,OwnerId from Account where id in : relatedAccountId]){

      // Requested not use the hard coded Ids in the code. This was just done to let you show it can be done.
      acc.OwnerId = '00528000000TxPV';
      updatedList.add(acc);
      }
      update updatedList;
      }

      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

    Popular Salesforce Blogs

    Power up Your Digital Store with DemandBlue’s Salesforce B2B Commerce Implementation

    Blog in Salesforce Implementation

    Today, digitalization has become a norm for business practices, and there is nothing better you can do to support your digital business model than implementing…

    Automation, B2B Commerce, B2B Commerce Implementation, B2B Commerce Platform, B2B Companies
    LevelShift (formerly DemandBlue) Mar 29, 2022
    3,206  Views
    Salesforce consulting companies help your business grow

    How do Salesforce consulting companies help your business grow?

    Blog in Salesforce Consultant

    Salesforce has time and again proven to be the best platform-as-a-service cloud CRM in the world. At present, Salesforce is the most widely used cloud…

    Customer Experience, Salesforce Applications, Salesforce Apps, Salesforce Consultant, Salesforce Consultants
    Algoworks Aug 13, 2019
    6,615  Views
    Permission Sets in Salesforce

    Permission Sets in Salesforce - Get Started Guide

    Blog in Salesforce Training

    Introduction Permission sets are a collection of settings and permissions that allow the users to have additional access, which they have already got from their…

    Create Permission Set, Custom Permissions Sets, License, Login IP Ranges, Manage Assignment
    Rajat Shende Feb 21, 2022
    5,597  Views

    Popular Salesforce Videos

    Entrepreneurship in the Salesforce Ecosystem

    Entrepreneurship in the Salesforce Ecosystem

    Video in Salesforce Stories

    The Salesforce Women’s Entrepreneur Group is a group of women who have founded and own businesses in the Salesforce ecosystem. Our goal is to inspire,…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Ecosystem, Salesforce Video
    Pooja Apr 12, 2021
    2,051  Views
    Salesforce Tutorial | Salesforce Summer '20 Release

    Salesforce Tutorial | Salesforce Summer '20 Release

    Video in Salesforce Training

    It's time for another Salesforce release. In this video, we talk about all of the new features that the Summer '20 release will give us.…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Stimulus Consulting Jul 24, 2020
    1,891  Views
    Salesforce QA Interview Guidance Program

    Salesforce QA Interview Guidance Program

    Video in Salesforce Training

    Do you want to learn what it takes to clear a Salesforce QA interview? In this video, Bava Dharani Ganesan gives a detailed explanation of…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Tulika Wadhwani Oct 26, 2022
    1,724  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®.

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.