Apex Triggers - 36 (Deloitte Salesforce Interview Question)

Поділитися
Вставка
  • Опубліковано 28 лип 2024
  • 💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn / mycompany
    💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
  • Наука та технологія

КОМЕНТАРІ • 19

  • @samirbagade4719
    @samirbagade4719 Рік тому

    Thank You
    😇

  • @ankitdangre4790
    @ankitdangre4790 Рік тому

    I truly love your channel. Such creative videos you’ve on this channel. You’re working so hard... keep going buddy❤

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

      Thank you ankit keep watching❤️

  • @adeshtiwari5112
    @adeshtiwari5112 4 місяці тому

    don't you think you should first always create trigger and then triggerhandler apex class

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

    Ur doing great buddy .....and one more parallely do asynchronous apex scenario like batch apex future,queuable , schedule apex it will help ...

  • @user-yx2is5vj3m
    @user-yx2is5vj3m 10 місяців тому

    but Bhai this code cannot works on bulkification

  • @debanshukar9091
    @debanshukar9091 Рік тому

    You are doing great for the community can you please add the exception handling and as well as the test classes for a few triggers atleast.

    • @sfdcninjas
      @sfdcninjas  Рік тому

      Hi buddy sure upcoming series will on test classes

  • @KalyanGk0
    @KalyanGk0 11 місяців тому

    What is the experience of a candidate? for this scenario

  • @rutikgaikwad6717
    @rutikgaikwad6717 11 місяців тому

    Wrong Solution.. managerList is not populating correctly in case of bulk functionality. Suppose if someone bulk upload the users having different Team names then in that case managerList will fetch only 1 manager of any team & will assign to all users.

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

      Hi , the managerMap will only store one manager per team due to the limit 1 in the SOQL query. To resolve this issue you can remove that limit 1. Thanks

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

      @@sfdcninjas : What if that org contains more than 50,000 records

  • @user-fx8pi1jw8f
    @user-fx8pi1jw8f Рік тому +1

    Good initiative, Badal. But I do see a few checks that are not at all needed and could be removed.
    1. LN 8 of handler - no use of newUserList.isEmpty check as the list would never be null.
    2. LN 38 of handler - no use of managerMap.isEmpty, just managerMap.containsKey(userObj.Team__c) is fine.
    3, LN 42 of handler - no use of manager != null as it can never be null because you're never putting any null value in the map.
    In LN 36 there should be another check of userObj.Assign_Manager__c
    Also, isEmpty() is an empty check, not a null check.

    • @sfdcninjas
      @sfdcninjas  Рік тому

      Thanks for your support and suggestion sir

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

      I agree with you, few null checks were not needed, here is my apprach for this problem with few lines of code:
      handler class:
      public with sharing class userManagerHandler {
      public static void beforeInsert(List newUsers){
      list managers=[SELECT Id, Name, Manager__c, Team__c, Assign_Manager__c FROM User where team__c!=null and isActive=true];
      Map managerMap=new Map();
      //putting team name and managers in a map
      for(User use:managers){
      if(!managerMap.containsKey(use.Team__c)){
      managerMap.put(use.Team__c,use);
      }
      }
      //testing team and assign managers
      for(User users:newUsers){
      if(users.Team__c!=null && users.Assign_Manager__c==true){
      if(managerMap.containsKey(users.Team__c)){
      users.Manager__c= managerMap.get(users.Team__c).id;
      }else{
      users.addError('No manager available from '+users.Team__c+' Team');
      }
      }
      }
      }
      }
      trigger:
      trigger userManTrig on User (before insert) {
      userManagerHandler.beforeInsert(Trigger.new);
      }

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

    WRONG Solution, Code will not work for bulkified scenario, it's a good practise to bulkfy triggers.