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 we get List of sibling Contact in a Salesforce Trigger?

    Tagged: Account, Contact Record, Salesforce List, Salesforce Trigger

    • Salesforce® Discussions

      How we get List of sibling Contact in a Salesforce Trigger?

      Posted by Shubham on August 4, 2017 at 6:41 AM

      I want a trigger on contact which prevent delete if there 3 more contact in same Account, please Write Trigger for it.

      • This discussion was modified 9 years, 3 months ago by  Shubham.
      • This discussion was modified 9 years, 3 months ago by  Forcetalks.
      • This discussion was modified 9 years, 3 months ago by  Forcetalks.
      Parul replied 8 years, 1 month ago 3 Members · 2 Replies
      • Account
      • Contact Record
      • Salesforce List
      • Salesforce Trigger
    • 2 Replies
    • saloni gupta

      Member
      August 4, 2017 at 6:55 AM

      Hi Shubham,

      You can refer this code for getting all the siblings of any contact.

       

      Set<id> accid = new Set<id>();
      for(Contact c : Trigger.old){
      accid.add(c.AccountId);
      }
      List<contact> con = [select id, accountid, Start_Date__c, End_Date__c from contact where Account.Id in : accid AND Id not IN : Trigger.old];

      Map<id,List<Contact>> mapAccIdCont = new Map<id,List<Contact>>();

      for(Contact c :con){
      if(mapAccIdCont.containsKey(c.Accountid)){
      List<Contact> conList = mapAccIdCont.get(c.AccountId);
      conList.add(c);
      mapAccIdCont.put(c.AccountId, conList);

      }
      else{
      List<Contact> conList = new List<Contact>();
      conList.add(c);
      mapAccIdCont.put(c.AccountId, conList);

      }
      }

    • [adinserter block='9']
    • Parul

      Member
      September 16, 2018 at 3:00 PM

      Trigger AreaCode on Contact (before insert) {

      Set <String> InitialContact Name = new Set <String> ();

      for(Contact Contact NameLoop : trigger.New)
      {
      if(ContactNameLoop.Area_Code__c != null){
      InitialContactName.add(ContactNameLoop.Area_Code__c);
      }

      }

      Map <String, Area_Code__c> matchingAreaCodeMap = new Map <String, Area_Code__c> ();

      for (Area_Code__c Record : [Select Id, Name, Market__c From Area_Code__c Where Name IN :InitialContactName])
      {
      matchingAreaCodeMap.put(Record.name, record);
      }

      for(Contact ContactNameLoop : trigger.New)
      {

      ContactNameLoop.Contact_Market__c = matchingAreaCodeMap.get(ContactNameLoop.Area_Code__c).Market__c;

      }

      }

       

      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

    Integrating Salesforce DevOps with Third-party Monitoring Tools

    Blog in Salesforce

    Employing third-party monitoring tools in conjunction with Salesforce DevOps is quickly becoming crucial for businesses that need to keep their Salesforce environment operating at peak…

    api-integration, CRM, Deployment Failures, DevOps Workflow, GDPR Compliance
    TechForce Jun 4, 2024
    938  Views

    The Salesforce Economy - What Does It mean for Your Business?

    Blog in Salesforce

    ❛ What’s happening at Salesforce isn’t just about Salesforce ❜ Twistellar has been working with Salesforce technologies for more than 5 years. We've seen businesses…

    Business, Cloud Computing, Cloud Services, Competitive Market, Consulting Partners
    Twistellar Aug 16, 2022
    3,922  Views

    Which is the Best Marketing Automation Tool?

    Blog in Others

    Selection of the best marketing automation tool is akin to picking your preferred ice cream flavour. There are many great options available, each with its…

    B2B, budget, Business Goals, Business Needs, Campaigns
    Codleo Feb 23, 2024
    1,462  Views

    Popular Salesforce Videos

    How the Salesforce Ecosystem Helped My Career

    How the Salesforce Ecosystem Helped My Career

    Video in Salesforce Stories

    Welcome back to 100DaysofTrailhead.com! Your involvement in the Salesforce Ecosystem can be a great boost to your career. In this video, Eric talks about the…

    Salesforce Tutorial, Salesforce Jobs, Salesforce Community, Salesforce Trailhead, Salesforce Developers
    Pooja Oct 1, 2021
    1,637  Views
    Creating Massive Junction Records with LWC | Salesforce Lightning Tutorial

    Creating Massive Junction Records with LWC | Salesforce Lightning Tutorial

    Video in Lightning, Salesforce Training

    Don't miss this new interchange session with Jorge Ortega and Alba Rivas! They'll discuss how to build an LWC that allows you to easily create…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Lightning Tutorial, LWC
    Rupal Kakkar Nov 15, 2021
    2,830  Views
    Send Salesforce Field Service Mobile App Device Logs For iOS

    Send Salesforce Field Service Mobile App Device Logs For iOS

    Video in Salesforce Training

    This video will demonstrate how to send device logs from the Field Service App for iOS / Android. Salesforce Support may ask you to send…

    Mobile app, Salesforce Video, Salesforce Learning, Salesforce Support, Salesforce Taining
    Praful Apr 13, 2021
    5,670  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.