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 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 9 years, 6 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

    application solution

    Popular Salesforce Blogs

    Providing Login Access Into The Salesforce Org With Limited Access To Salesforce AppExchange App Provider

    Granting Log-in Access Into Your Salesforce Org With Limited Access To Salesforce AppExchange App Provider

    Blog in Others

    Hi folks, Today we will learn, how to give grant access to Salesforce AppExchange App provider? There are many people who don't know how to…

    Lightning View, Salesforce AppExchange, Salesforce Lightning, Salesforce Lightning View User, Salesforce Org
    Prafull Oct 21, 2019
    6,055  Views

    The Salesforce Implementation Process: What Is It?

    Blog in Salesforce Implementation

    Salesforce implementation is the process of integrating and customizing the Salesforce platform to meet the specific needs of a business or organization. Salesforce is a…

    Benefits, Business, Campaign Tracking, Case Management, Centralized Platform
    Chris Jul 4, 2023
    1,757  Views
    Salesforce Training Program

    Best Salesforce Training Program In 2022

    Blog in Salesforce Training

    If you're seeking the best Salesforce training program to become a Salesforce developer in 2022, you've come to the correct place. Salesforce is a vast…

    Apex Programming, APEX Programming Language, App Cloud, Artificial Intelligence, Associate Instructors
    Taran Veer Jan 20, 2022
    5,085  Views

    Popular Salesforce Videos

    Salesforce Announces New Salesforce CDP Updates | Salesforce CDP

    Salesforce Announces New Salesforce CDP Updates | Salesforce CDP

    Video in Salesforce Products

    Salesforce, one of the largest global providers of CRM solutions, launched Salesforce CDP last year. Salesforce Customer Data Platform is an enterprise customer data platform…

    salesforce, Salesforce Video, Salesforce Learning, Customer Data, Salesforce News
    nakul singh May 31, 2021
    2,011  Views
    Salesforce - How to Create and Debug Process Builders

    Salesforce - How to Create and Debug Process Builders

    Video in Salesforce Training

    Check out this video on how to debug Process Builders. Once you really get into building processes in Salesforce in can be confusing as to…

    Salesforce Training, Salesforce Developer, salesforce, Salesforce Video, Salesforce Learning
    Bradley Jun 11, 2020
    1,937  Views
    Salesforce Security Review | Tutorial Video

    Salesforce Security Review | Tutorial Video

    Video in Salesforce Security

    If you ever wanted to publish an app, you probably know of the Salesforce security review. While dreaded by many developers, it is far from…

    Salesforce Training, Salesforce Tutorial, Salesforce Developers, AppExchange, Salesforce Video
    Prafull Mar 23, 2021
    3,285  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.