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, 1 month 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

    Lead Assignment

    Lead Assignment to the User in a Round Robin fashion | Salesforce Tutorial

    Blog in Salesforce Admin

    Balance your team's workload by automatically assigning new leads to each user.  A round-robin assignment means that all new leads will be assigned the same…

    Email Template, Fields & Relationships, Layout Properties, Lead Assignment, Lead Assignment Rule
    Amit Kumar Jun 10, 2022
    4,770  Views

    Salesforce Nonprofit Cloud Spring '24 Highlights

    Blog in Salesforce Releases

    While many of us are still feeling the chill of winter, Salesforce's Spring '24 release is in full bloom! Let's review some of the Nonprofit…

    Business Process API, Campaign ROI, Development, Donation Installments, Donor Records
    DB Feb 26, 2024
    1,399  Views
    Salesforce Development

    9 Salesforce Development Best Practices

    Blog in Salesforce

    Learning to code might be dreadful for a few of us, but all of us would like to tweak something the way we wish. Salesforce…

    App Building Process, app development, App Development Tools, AppExchange, Application
    Cloudideas May 28, 2021
    2,793  Views

    Popular Salesforce Videos

    Salesforce Integration: How to Do it the Best Way?

    Salesforce Integration: How to Do it the Best Way?

    Video in Salesforce Integration

    Once you deploy Salesforce solutions to improve the operation of your enterprise, your next logical step is to enhance the overall functionalities by integrating Salesforce…

    Salesforce Integration, Salesforce Integration Consultant, Salesforce Integration Cloud, Salesforce Integration Project, Salesforce Integration Services
    TechForce Jul 5, 2024
    723  Views
    Salesforce India Engineer Salary Revealed | Salary Break Up | Company Review

    Salesforce India Engineer Salary Revealed | Salary Break Up | Company Review

    Video in Salesforce Stories

    In this video, Soumyajit Bhattacharyay has given a detailed review of Salesforce. Talked about the tech stack that they work in. Talked about their offices…

    salesforce, Salesforce Developers, Salesforce Video, Salesforce Learning, Salesforce Job
    Nauman Apr 30, 2021
    2,626  Views
    5 Strategies to Get a Salesforce Job with No Experience

    5 Strategies to Get a Salesforce Job with No Experience

    Video in Salesforce Stories

    If you have questions like how to jump start your Salesforce career as a freshers? Or what should be your approach to start Salesforce career?…

    Salesforce Training, Salesforce Certifications, Salesforce Video, Salesforce Career, Salesforce Learning
    Pooja Jul 23, 2021
    1,894  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.