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 › 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 8 years, 5 months ago by  Shubham.
      • This discussion was modified 8 years, 5 months ago by  Forcetalks.
      • This discussion was modified 8 years, 5 months ago by  Forcetalks.
      Parul replied 7 years, 4 months 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);

      }
      }

    • 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

    application solution

    Popular Salesforce Blogs

    Salesforce Interview Questions

    Salesforce Interview Questions: Crack Any Salesforce Interview

    Blog in Salesforce Training

    To make sure you gain a detailed understanding of the types of questions you can expect during your job interview. We'll start by covering the…

    APEX Programming Language, Apex Triggers, Bucket Field, Business Logic, Client
    Taran Veer Dec 16, 2021
    6,080  Views
    Salesforce Partner

    Why Work With a Salesforce Partner? Here are All the Reasons

    Blog in Salesforce Consultant

    A lot of companies are looking to implement Salesforce as a valuable tool to help them automate processes, strengthen customer relationships, and more. Implementing Salesforce…

    Automate Process, automated process, Best Practices, Companies, CRM
    Cloudsquare Jul 25, 2022
    3,000  Views
    What is Pardot? What is Engagement History in Salesforce in 2023?

    What is Pardot? What is Engagement History in Salesforce in 2023?

    Blog in Others

    Pardot is a software as a service (SaaS) marketing automation platform by SalesForce offering email automation, targeted email campaigns, and lead management for B2B sales…

    Engagement History, Engagement History Dashboard, pardot, Pardot AI, Prospects and Leads
    Mohit Kumar Jan 10, 2023
    2,665  Views

    Popular Salesforce Videos

    Set Up a Microsoft Exchange Service Account to Sync with Salesforce (Using Command Shell)

    Set Up a Microsoft Exchange Service Account to Sync with Salesforce (Using Command Shell)

    Video in Salesforce Integration

    You can sync sales reps’ contacts and events between your Microsoft Exchange-based email and Salesforce using the Salesforce feature Lightning Sync. If you’re an Exchange…

    Salesforce Integration, Salesforce Lightning Experience, Salesforce Microsoft Integration, Microsoft Exchange Service Account Sync with Salesforce, Email Handling
    Jogender Feb 20, 2018
    4,926  Views
    Heroku | Salesforce Development Course

    Heroku | Salesforce Development Course

    Video in Salesforce Certifications, Salesforce Training

    Knowledge of Heroku is also required to crack the Salesforce PD 1 Certification Examination. Let’s understand what Heroku is and what are its uses, in…

    Salesforce Training, Salesforce Certification, Salesforce Video, Salesforce Learning, Heroku
    S2 Apr 8, 2022
    1,684  Views
    Soar: A Salesforce Philanthropy Film

    Soar: A Salesforce Philanthropy Film

    Video in Salesforce Stories

    When one of us is lifted up, all of us are lifted up. ? That's why we're supporting #GoGiveOne, a campaign to advance global vaccine…

    salesforce, Salesforce Philanthropy, Salesforce Video, Salesforce Learning, COVID-19
    Rupal Kakkar Sep 28, 2021
    2,419  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.