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 › 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 8 years, 7 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.

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

    application solution

    Popular Salesforce Blogs

    Salesforce Experience Cloud For Partners

    Blog in Salesforce Cloud Platform

    Unlocking Salesforce Experience Cloud's Potential for Partners In today’s digital world, companies are increasingly turning to technology to help them manage and optimize their partner…

    Campaigns, Certification Courses, Channel Support, Cloud-based Solution, Cloud-based Tool
    Emorphis Dec 20, 2022
    2,344  Views
    Choosing the Right Salesforce Implementation Consultant and Partner: A Comprehensive Guide

    Choosing the Right Salesforce Implementation Consultant and Partner: A Comprehensive Guide

    Blog in Salesforce Implementation

    Implementing Salesforce in a business to streamline its performance is a decision every e-commerce business makes to make its CRM project a real success. However,…

    Business Growth, Business Operations, Certified, Collaboration, Comprehensive Guide
    360degreecloud Salesforce Dec 7, 2023
    1,100  Views

    Everything You Need to Know about Salesforce Partner Portal

    Blog in Salesforce

    Implementing a robust partner portal becomes paramount as businesses strive to foster stronger partner relationships and expand their reach.  Salesforce Partner Portal offers a powerful solution…

    AppExchange, Best Practices, branding, Collaboration, Collaboration Tools
    CRMJetty Mar 27, 2024
    1,115  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®.

    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.