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 › Write a Salesforce Trigger for account name should be a combination of lastnames of all its related contacts

    Tagged: Account Detail, Contact Record, Record Processing, Salesforce Customization, Salesforce Trigger

    • Salesforce® Discussions

      Write a Salesforce Trigger for account name should be a combination of lastnames of all its related contacts

      Posted by Raghav Chaturvedi on June 22, 2017 at 6:58 AM

      Write a trigger for account name should be a combination of lastnames of all its related contacts. eg. if I have two contacts 1. test name 2. test name2 in an account. In this case account name should be "name name2". If I add a new contact "test name3" to this account, now account name should be "name name2 name3

      Raghav Chaturvedi replied 9 years, 3 months ago 2 Members · 9 Replies
      • Account Detail
      • Contact Record
      • Record Processing
      • Salesforce Customization
      • Salesforce Trigger
    • 9 Replies
    • Sudhir

      Member
      June 22, 2017 at 3:59 PM

      Check this out.. UpdateAccountNameFromContactLastName

      Update as per your trigger design template.

    • [adinserter block='9']
    • Raghav Chaturvedi

      Member
      June 23, 2017 at 1:33 AM

      sir in your trigger account name is updated by contact last name but i want the combination of both account name and contact last name

    • Raghav Chaturvedi

      Member
      June 23, 2017 at 2:38 AM

      trigger contactlastName on Contact (after insert,after update)
      {
      list lst=new list();
      for(contact c:Trigger.new)
      {
      lst.add(c.accountId);
      }
      list lac=new list();
      list lacc=[select Id,Name,(select Id,lastName from contacts) from account where Id in:lst];
      for(account a:lacc)
      {
      for(contact con: a.contacts)
      {
      a.Name=a.Name+' '+ con.lastName;
      lac.add(a);
      }
      }
      update lac;
      }

      this trigger works only one time,after run this trigger second related contact is not created,plz help

    • Sudhir

      Member
      June 23, 2017 at 7:35 AM

      I see that this is not mentioned this (account name should be combination of both account name and contact last name) in your first post here. Please make sure you have your requirement clear in the first instance.

      So your Account name should be "AccountName ContactLastName1 ContactLastName2 ContactLastName3 and so on" ?  Confirm and then I will update the code and post.

    • Sudhir

      Member
      June 23, 2017 at 8:48 AM

      Based on the assumption in my previous post, updated the code here..UpdateAccountNameFromContactLastName2

       

      This will work in all scenario - Insert, Update, Delete, Undelete of a Contact on an Account.

      • This reply was modified 9 years, 3 months ago by  Sudhir.
    • Raghav Chaturvedi

      Member
      June 23, 2017 at 8:48 AM

      yes in a account(Raghav),if we have 1 contact(lastNamme=kumar) then account name should we updated by(Raghav Kumar) and again we add a contact(lastnam=sharma)then account nae should we raghav kumar sharma and so on.

      this is my question

    • Sudhir

      Member
      June 23, 2017 at 8:50 AM

      Enjoy the updated code I posted a while ago.  🙂

    • Sudhir

      Member
      June 23, 2017 at 12:16 PM

      Did the solution work for you..

    • Raghav Chaturvedi

      Member
      June 23, 2017 at 12:28 PM

      yes and 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

    Popular Salesforce Blogs

    Salesforce Podcasts

    7 Salesforce Podcasts to Listen To in 2022-2023

    Blog in Salesforce

    If you work in Sales or Marketing, there’s no way you haven’t at least heard of the customer relationship management tool Salesforce. This software allows…

    Careers, Customer Communications, Customer Relationship Management Tool, Dreamforce, Freelance Engineers
    Madeline Miller Jun 13, 2022
    4,030  Views
    salesforce cpq

    Salesforce CPQ Certified Specialists - All You Need To Know

    Blog in Salesforce

    Salesforce CPQ is a program developed for providing correct pricing for any product configuration scenarios as a selling tool for the businesses. It also allows…

    Best Product, Block Pricing, Certification Exams, Contingency Plan, Contract Pricing
    Akhila Sep 1, 2020
    10,237  Views
    What is the Salesforce Analytics Cloud? | The Ultimate Guide

    What is the Salesforce Analytics Cloud? | The Ultimate Guide

    Blog in Salesforce Cloud Platform

    Welcome back to our page! Today, we are going to know about analytics cloud. Salesforce Analytics Cloud, also known as Salesforce Einstein Analytics, is a…

    Apps, Automate Service Processes, B2B Companies, Charts, Customer Interactions
    Akash Varshney Apr 3, 2023
    1,497  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.