Apex Triggers - 45 (Infosys Interview Scenario)

Поділитися
Вставка
  • Опубліковано 17 жов 2024

КОМЕНТАРІ • 30

  • @diobrando1253
    @diobrando1253 8 місяців тому +3

    Why did we use before? Here we are creating Contact based on some criteria right? Why did we not use after insert?

    • @kumareshghosh5593
      @kumareshghosh5593 8 місяців тому

      We only use "after" when we do DML on related records(child) , for the above same scenario, if he wrote the trigger on contact and do the update or insert on case, then "after insert" could have been used.

    • @diobrando1253
      @diobrando1253 8 місяців тому

      @@kumareshghosh5593 here case and contact are related and based on some criteria we are creating contact and assigning case to contact.
      I got to know (researched a bit) we are inserting contact while inserting case hence using before bcoz we don’t have contact id while inserting case

    • @sfdcninjas
      @sfdcninjas  8 місяців тому +1

      hello guys , there is a simple hook by which you can easily understand when to use before and when to use after trigger.
      The hook is if you are modifying/updating/changing same object record by which your code will be executed then in that case you have to use before trigger bcz you are just updating same record before it gets saved to database and if you are updating/modifying/changing related records lets say you are updating contact by account or opportunity by account then in that case you have to use after trigger.
      So Updating
      Same record - before trigger
      related record - after trigger

    • @diobrando1253
      @diobrando1253 8 місяців тому

      @@sfdcninjas hey thanks for reply, I really appreciate your efforts ❤️.
      But here we are using case to create contact right? That’s why I asked

    • @sfdcninjas
      @sfdcninjas  8 місяців тому +1

      Creating a contact is subtask but the main task is updating case object (same object on which we have our trigger) that’s why before trigger

  • @kumareshghosh5593
    @kumareshghosh5593 8 місяців тому +2

    I have recently attended few interviews and got many new trigger scnearios, let me know where to share with you, nice work!

    • @sfdcninjas
      @sfdcninjas  8 місяців тому

      Hi kumaresh thank you so much for this you can share those scenarios on linkedin
      www.linkedin.com/in/badal-chaudhary-296464149?
      else you can share it on my mail
      ninjasfdc@gmail.com

    • @angaditheru7080
      @angaditheru7080 8 місяців тому

      Can you please share here as well 🙏🏻

    • @kumareshghosh5593
      @kumareshghosh5593 8 місяців тому

      1. whenever a contact insert or update, if it's parent account has already 2 contact, prevent adding new contact insert or update
      2. whenever new opportunity gets closed , make sure the profile of the user is system administrator, else add error that only system admin can do DML operation on opportunity
      3.Three cutom object: country, state,city: state is child of country and city is child of state, whenever new city get's inserted or updated, make sure a custom field on coutnry name "city count" get's updated with the actual city count.
      4. **not a trigger: a custom field exist on account name: average case resolution day: which should have the average case resolution day count in the custom field. (Hint: create 2 maps to store id and total case count and id and find resolution day by closedDate-startDate ,then divide by case count to get the average).
      Let me know if you guys need the solution as well.

    • @angaditheru7080
      @angaditheru7080 8 місяців тому

      @@kumareshghosh5593 Yes,if possible you can share that as well

    • @SfDev-zd9mu
      @SfDev-zd9mu 8 місяців тому

      @@kumareshghosh5593 Hey bro appreciate you sharing the questions, the 3rd scenario is grandparent update isn't it?
      So first we will query parents from Child that are getting inserted then query grandparent form parent and then we can use Aggregate query and store count in grandparent field right?

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

    Thanks for sharing the knowledge. It's very great explanation. It could have more meaningful if the newly created contact is populated with the account which is same as case account.

  • @NitishKumar-sk3yi
    @NitishKumar-sk3yi 4 місяці тому

    One Question : Why can't we do this scenario in after context ?

  • @goldylodhi2116
    @goldylodhi2116 8 місяців тому +2

    Great explanation

  • @arunimakashyap6207
    @arunimakashyap6207 8 місяців тому +2

    Great and helpful video

  • @abhijit14820
    @abhijit14820 8 місяців тому +2

    Nice explanation sir🙏

  • @goldylodhi2116
    @goldylodhi2116 8 місяців тому +2

    Good

  • @mitalithakur2904
    @mitalithakur2904 8 місяців тому +1

    Good 🎉

  • @shivam_diwan
    @shivam_diwan Місяць тому

    sorry for increasing the like count from 69 to 70😂😂....good scenario though👍👍

  • @mirthishraj.r5462
    @mirthishraj.r5462 8 місяців тому +1

    I got this error CaseSuppliedEmailTrigger: execution of AfterInsert caused by: System.FinalException: Record is read-only Class.CaseSuppliedEmailTriggerHandler.LinkCaseWithContactAtInsert: line 28, column 1 Trigger.CaseSuppliedEmailTrigger: line 3, column 1

    • @sfdcninjas
      @sfdcninjas  8 місяців тому

      Hi please share your code

    • @SfDev-zd9mu
      @SfDev-zd9mu 8 місяців тому

      PRobably you are calling your logic in After event