Apex Triggers - 16 (TCS Interview Question)

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ต.ค. 2024

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

  • @rajeshwanve3834
    @rajeshwanve3834 ปีที่แล้ว +4

    Use the map and set and avoid the inner soql query because if the inner query has record more than 10000 then you will get an error

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

      Thank you for your suggestion 🙂

  • @ganeshrajput2491
    @ganeshrajput2491 7 หลายเดือนก่อน

    Thanks for video
    Bro your code is to lengthy you can minimise line of code as Salesforce orgs limit on line codes in org

  • @PANKAJKUMAR-fe8zn
    @PANKAJKUMAR-fe8zn ปีที่แล้ว

    Thank you very much Badal bhai for adding real interview question. please add as much as possible trigger interview scenario questions.

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

      Thank you so much Pankaj bhai

  • @AbhilashBanpurkar
    @AbhilashBanpurkar ปีที่แล้ว +3

    Discuss more such triggers your content is very good

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

      Thank you Abhilash, more trigger scenarios coming soon dont worry

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

    Very helpful ❤

  • @mozh826
    @mozh826 11 หลายเดือนก่อน

    İf we don’t use last else in helper class for . İt would be correct?

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

    Very nice sir

  • @Fury0710
    @Fury0710 4 หลายเดือนก่อน

    Will this code give right output when inserting mass opportunitues on multiple accounts? as parentIds set will contains I'ds for multiple accounts.

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

    Hello Sir, I have faced same scenario in one of my interviews but in addition to this they have asked me , if 2 opportunities have same maximum amount then they both oppty name should populate over the account, can you please cover that scenario as well?

    • @chandrasekharsf2556
      @chandrasekharsf2556 7 หลายเดือนก่อน

      in that case you have to remove query limit and get loop over opportunities to get highest valued opportunities in another list or set and use that set to populate names as a comma separated values

  • @NehaPandey-i9h
    @NehaPandey-i9h ปีที่แล้ว

    I have one doubt Where we have received trigger.old value in Handler class from Trigger for After Delete operation

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

      hi buddy we are passing it from our trigger in handler class

  • @anuragg7007
    @anuragg7007 10 หลายเดือนก่อน

    Hi, I used Aggregate Result query instead of nested SOQL query. For delete operation, my code is not working. Can you tell me why is not working?

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

      Please show me your code

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

    Superb

  • @gauravjoshi3879
    @gauravjoshi3879 8 หลายเดือนก่อน

    can we do this with the help of aggregate query

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

      yes we can do it by using aggregate query

  • @shubhamsri.1895
    @shubhamsri.1895 ปีที่แล้ว

    Bro if we are writing this code in Trigger Class then where we should write the trigger context (trigger.isDelete) and what code we have to write under is delete.
    Pls clear it

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

    Hi , I have one confusion here why we adding Name in MaxOpp ? it should be amount . On time 7.10

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

      Hi Dharmesh, buddy according to scenario we need to show opportunity NAME that has the highest amount 🙂.

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

      @@sfdcninjas Ok Got it , MaxOpp__c type should be string . Thank you so muchh!!

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

    Can you please do a video on howto find top most account on an account

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

    Fir whoch ur experience person this question is? Explain?

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

      It was asked to 2.1 yr of experience

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

      Thank you, please mention which exp person faced these question, please mention in the comment section so that we get clarity. Thank you

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

      i am really Sorry lokesh but i can’t disclose candidate’s name

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

      @@sfdcninjas no sir just tell is it experience question or not in the comment section, if exp then which level that's it

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

    in Line no44 why im getting "Illegal assignment from String to Decimal" Error??

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

      Hi Ankit can you please show your code it seems that you are assigning a String value to a Decimal variable

    • @Feel-2-Heal-Minds
      @Feel-2-Heal-Minds ปีที่แล้ว

      ankit check field type

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

    @sfdcninja can you please share the code?

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

      Hi Rahul , you can access code on salesforce geek website

    • @srisadgurusairam1688
      @srisadgurusairam1688 2 หลายเดือนก่อน

      @@sfdcninjas can you please provide the link here

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

    Sir , are these scenarios are on fresher level?

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

      these scenarios are for both fresher and experienced

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

    sir plz provide word or pdf document so candidate can easy to save coding

  • @memesv3.093
    @memesv3.093 ปีที่แล้ว +3

    Here's a different approach. Feedback and suggestions are welcomed
    trigger OpportunityTrigger on Opportunity (after insert, after update, after delete, after undelete) {


    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete)){
    Set accIds = new Set();
    for(Opportunity opp: Trigger.new){
    accIds.add(opp.AccountId);
    }

    List aggrList = [Select Name, AccountId, MAX(Amount) maxAmt from Opportunity
    where Amount!=null and AccountId IN: accIds
    group by Name, AccountId ORDER BY MAX(Amount) desc limit 1];

    List accList = new List();
    for(AggregateResult aggr: aggrList){
    Id accId = (Id) aggr.get('AccountId');
    String oppName = (String) aggr.get('Name');
    Decimal maxOppAmount = (Decimal) aggr.get('maxAmt');
    Account acc = new Account(Id= accId, Opp_having_Max_Amount__c=oppName);
    accList.add(acc);
    }

    update accList;
    }

    //-- For Delete

    if(Trigger.isAfter && Trigger.isDelete){
    Set accIds = new Set();
    for(Opportunity opp: Trigger.old){
    accIds.add(opp.AccountId);
    }

    List aggrList = [Select Name, AccountId, MAX(Amount) maxAmt from Opportunity
    where Amount!=null and AccountId IN: accIds
    group by Name, AccountId ORDER BY MAX(Amount) desc limit 1];

    List accList = new List();
    for(AggregateResult aggr: aggrList){
    Id accId = (Id) aggr.get('AccountId');
    String oppName = (String) aggr.get('Name');
    Decimal maxOppAmount = (Decimal) aggr.get('maxAmt');
    Account acc = new Account(Id= accId, Opp_having_Max_Amount__c=oppName);
    accList.add(acc);
    }

    update accList;
    }



    }

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

    i have confusion at 27 line that is else part else{parentIds.add(newopp.AccountId); used for insert, delete and undelete if oldmap = null, in delete operation old records are present in trigger.old. why should we take oldmap = null ;

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

      Hi , The reason for setting oldMap to null in the else part of the code is to handle the case where the trigger is fired on an insert, delete, or undelete operation. In all these cases, there is no old record to compare with the new record, so the oldMap parameter is set to null to avoid a null pointer exception when trying to access the old record.