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

    Benefits of Salesforce for FinTech: Boosting Efficiency and Scaling Growth

    Blog in Salesforce Implementation

    In recent years, the FinTech industry has boomed and transformed how people manage money, invest, and access financial products. However, with this growth, FinTech organizations…

    Automated Workflows, Benefits of Salesforce, Business Scalability, Cloud Based CRM, Collaboration Tools
    Bacancy Jun 10, 2024
    586  Views
    How to Display Images from File Tab to Salesforce App by using Aura Component?

    How to Display Images from File Tab to Salesforce App by using Aura Component?

    Blog in Others

    What are Aura Components? Aura components are a type of user interface framework used in Salesforce. They are built using the Aura framework, which is…

    Apex Server Call, APIs, Aura Component, Aura Components, Aura Framework
    Rupesh Pandey Apr 13, 2023
    2,027  Views

    Learn All About Salesforce Industry Clouds

    Blog in Salesforce Products

    The world today is undergoing a process of extreme digitization that reaches all sectors and industries of society. Undoubtedly, the Covid-19 pandemic was an important…

    Automation of Tasks, Boosts Growth, Business, Buying Process, Cloud Solutions
    SkyPlanner Aug 12, 2022
    3,394  Views

    Popular Salesforce Videos

    How to Switch your Career from Being an HR or a Recruiter to a Salesforce Developer/QA or a BA

    How to Switch your Career from Being an HR or a Recruiter to a Salesforce Developer/QA or a BA

    Video in Salesforce Stories, Salesforce Training

    In this video, Shrey has answered one of the most frequently asked questions about how someone who is working in HR or as a Recruiter…

    Salesforce Training, Salesforce Jobs, Salesforce Certification, Salesforce Developer, Salesforce Video
    Prafull May 7, 2021
    2,550  Views
    Einstein For Marketing Cloud | The Learning Guide

    Einstein For Marketing Cloud | The Learning Guide

    Video in Others

    AI has made things easy and smooth for any automation process. Einstein for Marketing Cloud provides insights and data to inform the content and timing…

    CRM, Salesforce Einstein, Marketing Automation, Salesforce Marketing Cloud, Marketing Cloud
    Cyntexa Feb 9, 2023
    1,255  Views
    Creating a To-do List with Custom Events | Salesforce Developer Quick Takes

    Creating a To-do List with Custom Events | Salesforce Developer Quick Takes

    Video in Others, Events, Salesforce Training

    Creating a ToDo list will show us how we can take data from one component and pass it to another. In our ToDo list component,…

    Salesforce Training, Salesforce Tutorial, Salesforce Developer, Salesforce Video, Salesforce Learning
    Jogender Mar 3, 2021
    1,525  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

    © 2025 - 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.