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

    Popular Salesforce Blogs

    Zero-Downtime Commerce Migration Moving from Legacy E-Commerce to Salesforce Commerce Cloud

    Zero-Downtime Commerce Migration: Moving from Legacy E-Commerce to Salesforce Commerce Cloud

    Blog in Salesforce

    Every hour of downtime on a retail site drains money. Industry research pegs enterprise downtime costs at $1 million or more per hour, and some…

    Salesforce Commerce, Salesforce Commerce Cloud
    James Jul 8, 2026
    737  Views
    Workbench in Salesforce

    How to Use Workbench in Salesforce | Developer Guide

    Blog in Others

    Workbench can be a web-based tool that helps administrators and developers to act with Salesforce for information Insert, Update, Upsert, Delete, and Export. It in…

    API, Bulk CSV, Case House Owners, Case Object, Case Owner Field
    Ratnesh Oct 9, 2020
    5,339  Views
    Sales Cloud

    Salesforce Sales Cloud Basics - An Overview

    Blog in Sales, Salesforce Cloud Platform

    In this top salesforce blog, we will be discussing, the basics of Salesforce Sales Cloud and What is the Purpose of Sales Cloud in Salesforce.…

    Best Leads, Better Technique, Business, Cell Phones, Client Data
    Ratnesh Apr 19, 2021
    9,322  Views

    Popular Salesforce Videos

    Introduction to Lightning Web Components (LWC)

    Introduction to Lightning Web Components (LWC)

    Video in Others

    Why Lightning Web Component (LWC) Part 1 - Vanilla HTML5 Web Components Benefits of Web Component Pillars of Web Component Demo of Custom Element and…

    Salesforce Lightning Components, Easy Way To Learn Salesforce, How To Learn Salesforce Lightning, Best Salesforce Tutorials, Salesforce Lightning Tutorial
    Apex Feb 11, 2019
    5,094  Views
    How to Use Salesforce for Project Management

    How to Use Salesforce for Project Management

    Video in Salesforce Stories

    When you think of CRM software, "Salesforce" is probably one of the first words that comes to mind. But Salesforce can do so much more…

    Salesforce Training, salesforce, Salesforce Video, Salesforce Learning, Salesforce AppExchange
    Nauman Aug 16, 2021
    2,721  Views
    7 Lightning Flow Features in Salesforce Winter '20 Release

    7 Lightning Flow Features in Salesforce Winter '20 Release

    Video in Others, Lightning

    Lightning Flow Builder is an automation tool within salesforce.com CRM. It's declarative, clicks not code, a tool that can perform both fully automated and custom…

    Salesforce Lightning, salesforce platform, Salesforce VIdeos, Lightning Flow Builder, Cloud Designer
    Pooja Feb 27, 2020
    2,398  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.