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

    Idea Management on Experience Cloud: Transforming Business Innovation

    Blog in Salesforce Products

    In today's fast-paced and highly competitive business landscape, innovation is paramount to staying relevant and thriving. Continuously generating fresh and inventive ideas is essential for…

    Business, Business Innovation, Business Needs, Business Performance, Community Engagement
    Advanced Oct 23, 2023
    1,254  Views

    No Code, Salesforce and SharePoint Integration

    Blog in Salesforce integration

    Salesforce no doubt is the world's best CRM, it helps organizations building meaningful relationships with their customers. However, there are certain areas where integrating external…

    Client ID, Client Secret, Consumer Key, Consumer Secret, Customers
    Apphienz May 10, 2021
    2,690  Views

    The Scope Expansion of Salesforce Projects: Control It with Skilled Consultants

    Blog in Salesforce

    Does your Salesforce project keep growing beyond its original plan? You're not alone. Salesforce implementations often grow beyond their original scope as businesses find new ways to use…

    Elena Jan 20, 2026
    37  Views

    Popular Salesforce Videos

    Salesforce Lightning Training - Creating Hello World Lightning Component

    Salesforce Lightning Training - Creating Hello World Lightning Component

    Video in Lightning, Salesforce Training

    Data Loader is a utility to perform bulk database operation. Recently Salesforce has changed the way data loaders need to be install. I explain end…

    Salesforce Training, Salesforce Lightning, salesforce, Salesforce Lightning Training, Salesforce Video
    Sam J Apr 28, 2020
    2,337  Views
    Salesforce Business to Consumer (B2C) Solution Architecture

    Salesforce Business to Consumer (B2C) Solution Architecture

    Video in Salesforce Stories

    Salesforce Business to Consumer (B2C) Solution Architecture Introduction, 05 min -Case Study – A Retail Company Journey -A need for Multi-Cloud Solutions -Salesforce B2C Solution…

    Salesforce Training, Salesforce Video, Salesforce Learning, Salesforce Business, Company
    Prafull Jun 23, 2021
    1,523  Views
    5 Steps to Faster Case Resolution | Salesforce Support

    5 Steps to Faster Case Resolution | Salesforce Support

    Video in Salesforce Stories

    When it comes to filling out a Salesforce case from, the description field and attached files are key to fast routing and resolution. Here are…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Abhishek Feb 11, 2022
    1,906  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.