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

    Salesforce Development Vs. Traditional Development

    Blog in Salesforce

    The competitive nature of present living standards has always kept every individual in the race for success. The urge to grab the crown and be…

    Best Security, Building and Managing CRM Apps, Business, ButtonClick Admin, CLOUD
    Gopal Krishna Mishra Oct 9, 2020
    3,264  Views
    Delete Records

    Learn How to Delete Records Using Flows in Salesforce | The Developer Guide

    Blog in Salesforce Apex

    Go to Setup, enter flow in Quick Find then select Flows.  Click on New Flow. From the template, select Screen Flow.  Click on the +…

    API Name, Condition Requirements, Custom Label, Delete Record Element, Delete Records
    Aryan Ujlayan Jul 12, 2022
    5,406  Views

    Salesforce Automation with Flow

    Blog in Others

    Following on from the previous article on Salesforce automation tools, this time we cover automation using the brand-new Flow Builder tool (as released in Feb 2019). This…

    Apex Triggers, Cloud Platform, Flow Builder, Lightning App Builder, Process Builder
    KeyNode May 17, 2019
    4,517  Views

    Popular Salesforce Videos

    Learning Path and Pay Scale for Salesforce Profiles

    Learning Path and Pay Scale for Salesforce Profiles

    Video in Salesforce Training

    Now it's high time to know about the Learning Path for the different Salesforce profiles. In this video, you also got to know about the…

    Salesforce Training, Salesforce Tutorial, Salesforce Jobs, Salesforce Ecosystem, Salesforce Video
    S2 Jan 24, 2022
    2,259  Views
    The Future of Salesforce Security and Authentication

    The Future of Salesforce Security and Authentication

    Video in Salesforce Security

    Learn how to enable the best security in a way that will have your users thanking you. Be the first to learn about the next-gen…

    Salesforce Security, Cloud Computing, User Setup, Security And Access, User Experience
    Ashley May 8, 2018
    2,187  Views
    How to Logging Automated Emails on Related Records

    How to Logging Automated Emails on Related Records

    Video in Salesforce Admin

    Learn how to logging automated emails on related records. We will show you how to create a process builder using the package Send Emails. This…

    Salesforce Training, Salesforce Tutorial, Process Builder, Salesforce Video, Salesforce Learning
    SkyPlanner Nov 1, 2022
    1,777  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.