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 Create a Batch class which append Account's name after each related contact in Salesforce?

    Tagged: Account Name, Batch Class, Contacts, Multiple Accounts, Parent Account, Related Contact, Salesforce Junction Object

    • Salesforce® Discussions

      How to Create a Batch class which append Account's name after each related contact in Salesforce?

      Posted by Prachi on December 9, 2019 at 6:04 PM

      How to Create a Batch class which append Account's name after each related contact?

      Deepak replied 6 years ago 2 Members · 1 Reply
      • Account Name
      • Batch Class
      • Contacts
      • Multiple Accounts
      • Parent Account
      • Related Contact
      • Salesforce Junction Object
    • 1 Reply
    • Deepak

      Member
      December 10, 2019 at 2:44 PM

      I believe you are trying to associate a single contact to multiple accounts. This functionality was released in Spring 16' and is implemented through a Salesforce Junction object - AccountContactRelation.

      I assume you have already enabled this functionality through the UI and a parent Account is declared for this Contact.

      I have modified your code to associate the contact to all 20 account.

      global class UpdateProjectNameBatch implements Database.Batchable
      <sObject>
      { ID conId = '0037F00000IfCCKQA3'; //Add the contact Id here
      List<AccountContactRelation> ListInsertion = new List<AccountContactRelation>();
      String query = 'Select Id,Name FROM Account WHERE Name = 'SampleAccountOne'';

      global Database.QueryLocator start(Database.BatchableContext bc)
      {
      return Database.getQueryLocator(query);
      }

      global void execute(Database.BatchableContext bc,List<Account> batch){

      for (Account a : batch)
      {
      AccountContactRelation c = new AccountContactRelation();

      c.AccountId = a.id;
      c.contactId = conId;
      ListInsertion.add(c);
      }

      Insert ListInsertion;

      }

      global void finish(Database.BatchableContext bc)
      {
      //DoNothing.
      }
      }

    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

    How to Integrate Salesforce and NetSuite Effectively?

    Blog in Salesforce integration

    Salesforce is the worldwide leader in making revolutionary business applications, served from the cloud and are designed to help generate leads for an organization. Also, it…

    CRM Solutions, Customer Service, customization and integration, Salesforce, Salesforce API
    AwsQuality Oct 18, 2019
    5,029  Views

    Learn the Basics of LWC in No Time! | Salesforce Lightning Web Components

    Blog in Salesforce Tutorial

    Why Lightning Web Component (LWC)?  It was time for a change because the AURA framework, which served as the foundation for the current Lightning Components,…

    Aura Components, Aura Framework, Base Lightning Components, CSS, ForceCode Extension
    Pranjal Jan 2, 2023
    3,429  Views

    Learn All About Salesforce Einstein

    Blog in Salesforce Einstein

    Salesforce has expanded its cloud customer relationship management (CRM) software-as-a-service products by adding artificial intelligence (AI) through its Einstein brand, which launched in 2016. Since…

    App Cloud Users, Artificial Intelligence, Business Users, Calendar, Chatter Activity
    Apphienz Nov 18, 2021
    2,697  Views

    Popular Salesforce Videos

    Learn About the Salesforce Products in this Tutorial Video

    Learn About the Salesforce Products in this Tutorial Video

    Video in Salesforce Products

    Salesforce is a top-rated CRM that offers businesses a diverse range of products to enhance their business model and operations. With each Salesforce product specifically…

    Salesforce Training, Salesforce Products, Salesforce Sales Cloud, salesforce, CRM
    Vivek Jun 21, 2022
    2,884  Views
    Hands-on Experience in Salesforce

    Hands-on Experience in Salesforce

    Video in Salesforce Training

    How to get Hands-on experience in Salesforce? Watch this video to learn all about it.

    Salesforce Training, Salesforce Administration, Salesforce Online Training, Salesforce Developer, Salesforce Lightning Experience
    CRS Aug 17, 2022
    1,980  Views
    Lightning Component In Salesforce

    Lightning Component In Salesforce

    Video in Lightning, Salesforce Development

    In this video, we are going to look into: Lightning Component Lightning Component features Types of Lightning Component Lightning Component bundle Watch this video and…

    Salesforce Developer, Salesforce Lightning, salesforce, Salesforce Admin, Lightning Component Bundle
    kanika May 12, 2021
    1,646  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.