SOQL for Beginners - Part 2: Relationship Queries and Bonus Tips

Поділитися
Вставка
  • Опубліковано 7 вер 2024
  • We talk about relationship queries, from parent to child and child to parent. We also look at different unique SOQL functions that will save you a LOT of time.
    This is a must try!!

КОМЕНТАРІ • 5

  • @moenajim7812
    @moenajim7812 3 місяці тому

    Hi Pratima, Thanks for sharing!
    I think there is one mistake in 6:25 where you say that to refer to a parent you add __r (I think you meant __c)
    The __r is to refer to child in subqueries.

    • @PratimaShri
      @PratimaShri  3 місяці тому +1

      Oh shoot you are absolutely correct 🙈 I forgot to talk about custom fields altogether so added this voiceover and I totally misspoke. I use this on a daily so it’s quite embarrassing. Thank you for pointing it out. Pinning this comment for others to see.
      Will make a follow-up on custom fields.

  • @GauravSharma-ju4ic
    @GauravSharma-ju4ic 3 місяці тому +1

    Hi Pratima, very informative video.
    In recent interview, interviewer asked me query
    1). To fetch all accounts with the number of associated contacts with them.
    2). To fetch all accounts who have more than 2 contacts related to them.
    Can you tell me how to write these queries?

    • @PratimaShri
      @PratimaShri  2 місяці тому

      hey! You would have to write some Apex - here is an example: (i dont recommend using this without any filter as this is an expensive query and might run into SOQL limits)
      List accList = [SELECT Id,Name, (SELECT Id from Contacts) FROM Account];
      for(Account a : accList){
      System.debug('Count of Contacts for '+a.Name+ ' is ' +a.Contacts.size());
      }

    • @GauravSharma-ju4ic
      @GauravSharma-ju4ic 2 місяці тому

      @@PratimaShri Can you tell me if this is fine
      [SELECT COUNT(Id), AccountId FROM Contacts ORDER BY AccountId HAVING COUNT(Id) >= 2