Trigger to count number of Contacts with an account

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2021
  • #ProgrammingMadeEasy
    Hello and welcome to Programming Made Easy. In this video we would be discussing more on Triggers. In the Previous video we talked about sibling trigger, how to create it and the best practices involved. In this video we would be discussing more on triggers and the trigger for today is to count the total contacts associated with an account in salesforce.
    Trigger to count number of contacts associated with an account,
    Display the total number of contacts on account detail page,
    Count number of contacts on accounts using Trigger ,
    How do I find the number of contacts associated with an account in Salesforce?
    Count the Contacts in the related list of Account ,
    Salesforce | How can we count number of contacts ,
    How to use trigger to count number of contacts associated ,
    Salesforce Apex: How to Track the Number of Contacts,
    Trigger to update number of contacts associated with account,
    Salesforce: Trigger to count total no of contacts in an account ,
    Account Contact Trigger Scenario,
    Trigger scenario(when account address is updated related contact address also updates)

ความคิดเห็น • 53

  • @sumitkumarojha3251
    @sumitkumarojha3251 ปีที่แล้ว

    Awesome Man. Without using Map you have solved this problem very well.

  • @programtime5526
    @programtime5526 2 ปีที่แล้ว +1

    very helpful video sir . Thanks alot

  • @saiseshapu0074
    @saiseshapu0074 2 ปีที่แล้ว +1

    Great 👍

  • @arun6479
    @arun6479 2 ปีที่แล้ว +1

    Thanks Brother ..

  • @swatisharma-oz6df
    @swatisharma-oz6df 19 วันที่ผ่านมา +1

    Can you take this one in your next video. write a trigger to get the product count of opportunity and update count field on account

  • @lalitkatare3475
    @lalitkatare3475 ปีที่แล้ว +1

    Can you also add after delete event

  • @Abhishekkumar-pi9mu
    @Abhishekkumar-pi9mu 2 ปีที่แล้ว +1

    Good Code is Working

  • @slaidwar
    @slaidwar 2 ปีที่แล้ว +2

    why you put update accounts(); on line no 32 which is outside the if block, you can put this on line no 30 ... ???

  • @AnkitSharma-ok7ll
    @AnkitSharma-ok7ll 2 ปีที่แล้ว +1

    very helpful video

  • @Abhishek-yb9kb
    @Abhishek-yb9kb 2 ปีที่แล้ว +1

    Hello there, may i know why we are adding (Select Id from contacts) seperately in line 23, kindly guide I'm new in this domain

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว +2

      Hi Abhishek (Select Id from contacts) is used because we want the contacts of those accounts whose Id is present in our set. Basically this is an inner query and 1 to many relationship is being followed in here. This means that 1 account can have n number of contacts so If we want such type of thing we generally write this query. Since in here we were just concerned with the total contact size so only took Id , But if we have some other operation to do then we could have queried some other fields as last name etc all depending upon the scenario.
      Hope you understood.
      Thanks

    • @Abhishek-yb9kb
      @Abhishek-yb9kb 2 ปีที่แล้ว +1

      @@ProgrammingMadeEasy99 Thank you very much bro that you gave time to reply and explained.
      do you teach online also

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว +1

      Yes bro kindly mail me at programmingmadeeasy117@gmail.com

  • @padalapallavi2011
    @padalapallavi2011 ปีที่แล้ว +1

    How to get the count along with existing records? It is working only for newly created ones.

  • @nishantkumar-vv8pf
    @nishantkumar-vv8pf 2 ปีที่แล้ว +1

    why we didnt created another list for storing the updated no of count vaues

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว +1

      You can do that also but always remember 1 thing that map is more capable than list both in terms of space time so try using that. This is a beginner friendly video but in future videos we would be going more deep into these things

    • @nishantkumar-vv8pf
      @nishantkumar-vv8pf 2 ปีที่แล้ว

      @@ProgrammingMadeEasy99 thanks for the reply and valuable input sir...
      My question was as on line number 32...you did update accounts directly.. but usually we create a list and addd the records which we have updated ( like updatelist.add(acc)) and then we update that list (line number 32)
      But here you have directly updated .
      So what is the concept behind this that we can do directly the way u did n when we need to take another list put all update records n the update as a whole

  • @rajeevranjan3718
    @rajeevranjan3718 2 ปีที่แล้ว +2

    Very helpful video. can you provide the test class also for this?

  • @saurabhsp87
    @saurabhsp87 ปีที่แล้ว

    Why are we taking newlist and oldList? kindly explain

    • @mr.darksoul9109
      @mr.darksoul9109 ปีที่แล้ว +2

      newList will contain new values and oldList will contain old values

  • @shubhamkukwas3397
    @shubhamkukwas3397 2 ปีที่แล้ว +1

    can we do count Manually without using Inner query or aggregate query???? please reply

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว

      No

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว

      Assume the big picture let us say for 1 account you have 50000 contacts.then how would you approach that? So that's why automation is required

    • @shubhamkukwas3397
      @shubhamkukwas3397 2 ปีที่แล้ว

      @@ProgrammingMadeEasy99 but with the help of inner Query we can get only 50000 records what about millions of records then this code will fail right?

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว

      Yes sir. That's why always try to assume the big picture as a key to scalable solution

  • @akshayh5795
    @akshayh5795 2 ปีที่แล้ว

    Can we do this with a object with lookup relationship

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว

      Can you elaborate

    • @hariharannatarajan7208
      @hariharannatarajan7208 2 ปีที่แล้ว +1

      this kinda functionality is done for look up relationships only, because in master detail relationship we have roll up summary to find the summary or count of the child records

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว

      The main aim of this video is to make you all understand how to think in Apex and moreover this is beneficial when you are giving your interviews as they generally give such type of scenarios to code in Apex.

  • @hariharannatarajan7208
    @hariharannatarajan7208 2 ปีที่แล้ว +1

    we should also write the logic for the after delete and after undelete operations then only the solution will be a complete one

  • @TOXIC_ThakurJi
    @TOXIC_ThakurJi ปีที่แล้ว +1

    Can u provide us handler code?

  • @avinashtayade3718
    @avinashtayade3718 2 ปีที่แล้ว +1

    how to create a field in account boj (total contact)

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว +1

      If you want to create a field you can go to setup then object manager search account and create new field. You could specify any data type for that.

    • @avinashtayade3718
      @avinashtayade3718 2 ปีที่แล้ว +1

      @@ProgrammingMadeEasy99 which data type (number) or (auto number)

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว

      Number field.

    • @avinashtayade3718
      @avinashtayade3718 2 ปีที่แล้ว +1

      @@ProgrammingMadeEasy99 ok sir but can you explain wich formula can use

    • @ProgrammingMadeEasy99
      @ProgrammingMadeEasy99  2 ปีที่แล้ว +1

      To get total contacts associated with an account you have to use code no formula is there for it.

  • @nikitaghai9248
    @nikitaghai9248 2 ปีที่แล้ว +2

    Great 👍