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

    Creating and populating a Wrapper in Apex

    Creating and Populating a Wrapper in Apex

    Blog in Salesforce Apex

    As Apex is a statically typed language, you must choose only one object type per list to iterate. What if you want to iterate an…

    Constructor, Custom Objects, Custom Wrapper Controller, Lightning Component, Member Variables
    Rajat Oct 12, 2018
    40,268  Views
    Get Salesforce Campaign Members Directly in MailChimp

    Get Salesforce Campaign Members Directly In MailChimp

    Blog in Salesforce Implementation, Salesforce integration

    For Email Marketing you have to add Salesforce Contacts directly into the MailChimp. So follow the steps to configure MailChimp for Salesforce and get the…

    Configure Mailchimp for Salesforce, MailChimp, MailChimp integration with Salesforce, Salesforce Campaign Members, Salesforce Campaigns
    PRANAV May 31, 2018
    6,672  Views
    Process Automation

    Salesforce Process Automation Best Practices

    Blog in Others, Salesforce, Salesforce Products

    Salesforce Process Builder was by far one of Salesforce Users' most helpful and popular features. Salesforce uses Process Builder to automate business operations. Relatively new…

    Apex Triggers, Approval Processes, Automated Conditions, Automated Email, Automation Activities
    Cymetrix Jun 24, 2021
    8,339  Views

    Popular Salesforce Videos

    Being a Sr. Salesforce Consultant | SFDC Consultant Podcast

    Being a Sr. Salesforce Consultant | SFDC Consultant Podcast

    Video in Salesforce Consultant

    What it is like being a Sr. Salesforce Developer at a consulting firm. What a day in Sr. Salesforce Consultant's life looks like. Struggles of…

    Salesforce Developer, Salesforce Consultant, Salesforce Consulting, SFDC, Salesforce Video
    Prafull Aug 4, 2020
    1,775  Views
    What is Salesforce Permission Sets? Explain in Details

    What is Salesforce Permission Sets? Explain in Details

    Video in Salesforce Admin

    Permission Sets basically deals with improvising the additional permission from the existing profile. Watch this video to learn more about Salesforce Permission Sets. If you…

    Salesforce Training, Salesforce Administrator, Salesforce Profiles, Rules in Salesforce, Salesforce Permissions
    CRS Feb 25, 2022
    2,090  Views
    Salesforce: Advanced 'Change Owner' Control in Flow and Apex

    Salesforce: Advanced 'Change Owner' Control in Flow and Apex

    Video in Salesforce Workflow

    Alex Edelstein explains the Salesforce feature known as the 'Change Owner' Control in Flow and Apex. This video is geared toward those already familiar with…

    Salesforce Training, Salesforce Tutorial, Salesforce Apex, salesforce, Apex
    Mayra Oct 21, 2022
    2,204  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.