Це відео не доступне.
Перепрошуємо.

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.

  • @swatisharma-oz6df
    @swatisharma-oz6df Місяць тому +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

  • @programtime5526
    @programtime5526 2 роки тому +1

    very helpful video sir . Thanks alot

  • @saiseshapu0074
    @saiseshapu0074 2 роки тому +1

    Great 👍

  • @arun6479
    @arun6479 2 роки тому +1

    Thanks Brother ..

  • @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 ... ???

  • @lalitkatare3475
    @lalitkatare3475 Рік тому +1

    Can you also add after delete event

  • @padalapallavi2011
    @padalapallavi2011 Рік тому +1

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

  • @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

  • @Abhishekkumar-pi9mu
    @Abhishekkumar-pi9mu 2 роки тому +1

    Good Code is Working

  • @AnkitSharma-ok7ll
    @AnkitSharma-ok7ll 2 роки тому +1

    very helpful video

  • @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?

  • @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

  • @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

  • @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

  • @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.

  • @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.

  • @TOXIC_ThakurJi
    @TOXIC_ThakurJi Рік тому +1

    Can u provide us handler code?

  • @nikitaghai9248
    @nikitaghai9248 2 роки тому +2

    Great 👍