Apex Triggers - 12 (Trigger Interview Question)

แชร์
ฝัง

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

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

    Very useful

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

    Keep it up brother, waiting for new videos .
    ur videos so good and interview related

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

      Thanks for your support brother

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

      @@sfdcninjas aur videos kb daal rhe ho

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

    Sir just out of curiosity sir I have never seen so many null check as u said it's best practices so while working in real-time is it required to use all the null check or u can ignore some

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

      You can ignore null check but it is always a good practice to apply a null check to avoid null pointer exception in apex.

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

      @@sfdcninjassir can we use safe navigation operator instead of this if statement

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

    At the end can we create list and add acc like insert list ? Wil it has same.result?

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

      yes you can use list or map for dml operations

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

    Bro do some real-time batch apex example also

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

    Hi bro, if we insert two case records with same account id at the same time then which record's case number will be populated in account? Please do answer

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

      Hi Abhishek , if two case records with the same account ID are inserted at the same time, the case number of the last inserted case record will be populated in the "Latest_Case_Inserted__c" field of the corresponding account.

  • @user-lh6uu9iv6l
    @user-lh6uu9iv6l 7 หลายเดือนก่อน +2

    Thank you for this wonderful series. I have just tried another approach and its working fine too.
    Code:
    trigger LatestCaseInserted on Case (after insert) {

    if(trigger.isAfter && trigger.isInsert){
    Map caseMap = new Map();

    for(Case cs : trigger.new){
    if(cs.AccountId != null){
    caseMap.put(cs.AccountId,cs);
    }
    }

    List caseList = [Select Id,CaseNumber,AccountId from Case where AccountId IN : caseMap.keySet()];
    Map accountUpdateMap = new Map();

    for(Case cs : caseList){
    Account ac = new Account();
    ac.Id = cs.AccountId;
    ac.Latest_Case_Inserted__c = caseMap.get(cs.AccountId).CaseNumber;
    accountUpdateMap.put(ac.Id, ac);
    }

    if(!accountUpdateMap.isEmpty()){
    update accountUpdateMap.values();
    }

    }

    }

    • @sfdcninjas
      @sfdcninjas  6 หลายเดือนก่อน

      Nice one

    • @diobrando1253
      @diobrando1253 5 หลายเดือนก่อน

      why do u need caselist? u can iterate over trigger.new directly na? rest logic is fine using map is nice, but why did u query case list? we can use trigger.new and while new record will get in DB we can attach case number to acc field