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, 2 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

    Salesforce Pardot vs Hubspot - Complete Breakdown

    Blog in Salesforce Products, Salesforce Tools

    Pardot Vs Hubspot – An end-to-end comparison of Features, Pricing & Integrations First things first. Whether you opt for Pardot or Hubspot, it’s all about…

    Articles, Automate Marketing Tasks, Automation and Campaigns, Automation Rules, Automation Workflow
    LevelShift (formerly DemandBlue) Jul 19, 2021
    5,629  Views

    Salesforce Commerce Cloud: Maximizing Revenue

    Blog in Salesforce Cloud Platform

    In the ever-evolving world of e-commerce, staying ahead of the competition and delivering exceptional customer experiences is critical. With the advent of Salesforce Commerce Cloud,…

    Applications, Australia, Automate Marketing Campaigns, Benefits, Boost Conversion Rates
    Kizzy Consulting Aug 4, 2023
    1,567  Views

    Top Salesforce Winter '23 Service Cloud Features

    Blog in Salesforce Releases

    Now you can provide efficient and flexible services with Salesforce's latest Winter ‘23 expanded set of Service Cloud features. Not only that, you can handle…

    Case Classification and Flows, Connect Salesforce with Slack, Custom Actions, Customer Emails, Customer Issues
    Apphienz Sep 15, 2022
    2,040  Views

    Popular Salesforce Videos

    Translation Workbench | Salesforce Tutorial

    Translation Workbench | Salesforce Tutorial

    Video in Others, Salesforce Training

    One of the most common questions new Salesforce admins ask us is how can they translate custom terms when their org is in multiple languges?…

    Salesforce Training, Salesforce Tutorial, Salesforce Admins, Salesforce Video, Salesforce Learning
    Stimulus Consulting Oct 1, 2020
    2,594  Views
    Add Intelligence to Any Salesforce App with Einstein Discovery

    Add Intelligence to Any Salesforce App with Einstein Discovery

    Video in Salesforce Einstein

    Bring intelligence in the context on any Force.com app thanks to the power of Einstein Data Discovery. Any Salesforce Admin or Developer can add in…

    Salesforce Developer, Salesforce Process Builder, Salesforce Applications, Salesforce Einstein, Machine Learning
    Ashley Nov 23, 2018
    1,912  Views
    Use Salesforce CMS to Manage and Publish Content for Experience Cloud Sites

    Use Salesforce CMS to Manage and Publish Content for Experience Cloud Sites

    Video in Salesforce Cloud Platform

    Learn how Salesforce CMS helps you create, manage, and publish your content in Experience Cloud. With Salesforce CMS, you can also customize content for specific…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Jogender Apr 25, 2022
    2,678  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.