06 Trigger & Test Class Scenario| After Insert | Populate Latest Case No on Account on Case creation

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ย. 2022
  • studysalesforce.com/ [Find all Salesforce Video links]
    Udemy : Enroll Salesforce Admin Certification Masterclass : kadge.io/admin201
    Udemy : Enroll Salesforce PD1 Certification Masterclass : kadge.io/pd1
    Udemy : Enroll Salesforce Flow Builder Masterclass: kadge.io/flowbuilder
    For Instructor Led Training
    Email: sanjaygupta.techschool@gmail.com or
    Visit: studysalesforce.com/
    Connect with Sanjay Gupta:
    Linkedin: / sanjay-gupta-bb2a79bb
    Find Below: TH-cam Playlist Links for Salesforce Videos
    Salesforce Administrator (Lightning Experience) Video Series
    • 01 How to create Devel...
    2022 | Salesforce Flow Scenarios
    • 01 Screen Flow Scenari...
    Aura Component Development
    • 01 Introduction to Lig...
    Apex Programming | Apex Test | Async Apex in Salesforce
    • 01 Introduction to Ape...
    Salesforce Interview Preparation Videos
    • What is workflow rule ...
    Flow Builder in Salesforce Lightning Video Series
    • What is Flow Builder i...
    Apex Triggers in Salesforce
    • 01 Introduction to Ape...
    Asynchronous Apex in Salesforce
    • 01 Introduction to Asy...
    Process Builder in Salesforce Lightning Video Series
    • What is process builde...
    Workflow Rule in Salesforce Video Series
    • What is workflow rule ...
    Report & Dashboard in Salesforce Video Series
    • Introduction to Report...
    Data Security in Salesforce Video Series
    • Introduction to Data S...
    #Salesforce #lightning #development #flow #admin #salesforceadmin #salesforcetraining #learnsalesforce #interview #salesforcedeveloper #developer #sanjaygupta #sanjayguptatechschool #studysalesforce #apex #trigger #integration #lwc #aura #lightningwebcomponent

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

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

    Udemy : Enroll Salesforce Flow Builder Masterclass: kadge.io/flowbuilder
    Udemy : Enroll Salesforce Admin Certification Masterclass : kadge.io/admin201
    Udemy : Enroll Salesforce PD1 Certification Masterclass : kadge.io/pd1
    For Instructor Led Training
    Email: sanjaygupta.techschool@gmail.com or
    Visit: studysalesforce.com/
    Connect with Sanjay Gupta:
    Linkedin: www.linkedin.com/in/sanjay-gupta-bb2a79bb/

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

      5:44 sir in my trigger its shows that Illegal assignment from string to Decimal... What to to now ??

  • @praveenkokkirala
    @praveenkokkirala ปีที่แล้ว +7

    why we have to create an instance of Account and fill the values? if the account is already present , can't we just query the account and fill "Latest case num" field?

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

      trigger CaseTrigger on Case (after insert) {
      if(Trigger.isAfter){
      if(Trigger.isInsert){
      CaseTriggerHandler.populateLatestCaseNum(Trigger.new);
      }
      }
      }
      ---------------------
      public class CaseTriggerHandler {
      public static void populateLatestCaseNum(List csList){
      List accList = new List();
      for(Case cs : csList){
      for(Account acc : [SELECT id, Latest_case_Number__c FROM Account WHERE id =: cs.AccountId]){
      acc.Latest_case_Number__c = cs.CaseNumber;
      accList.add(acc);
      }
      }
      if(!accList.isEmpty()){
      update accList;
      }
      }
      }

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

    You are excellent guruji

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

    amazing video series

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

    Thank you Sir

  • @Abhishekkumar-pi9mu
    @Abhishekkumar-pi9mu ปีที่แล้ว +3

    Hi Sanjay Ji !!! Any update on the upcoming LWC playlist video.!!!

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

    Iam getting List index out of bound by following the above process mentioned in the video

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

    Can anyone please help me ,I'm writing the same code but still test case failed, actual is showing null

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

    Sir This is the code you have showed us and this is the codeBlock I have written
    public class CaseTriggerHandler {

    public static void populateLatestCaseNum(List caseList){

    List accList = new List();
    for(Case cs : caseList){
    if(cs.AccountId != null){
    Account acc = new Account();
    acc.Id = cs.AccountId;
    acc.Latest_Case_Number__c = cs.CaseNumber;
    accList.add(acc);
    }
    }

    if(!accList.isEmpty()){
    update accList;
    }
    }
    }
    The Problem is in Account the Field Called Latest Case Number there is no case number is visible after creating new account and creating the new case in the same account. Please guide me...
    ThankYou!

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

      check events in trigger by default its before events change to after

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

      ​@@bandaruchaitanya2038in my case its hows illegal statement string to decimal , wht to do in version 58

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

      @@ronnygamerz88 change your field(latestcasenumber) datatype to text

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

    this code is not working when we try to create cases in bulk for a particular account.
    @SanjayGuptaTechSchool

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

      So in bulk case the one which gets inserted last that case number will be populated.

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

      @@SanjayGuptaTechSchool Sir, the code will not work, If we go for bulk Insertion of Case records, it will show
      duplicate Id error as List will contain Duplicate Id, To remove this we need to convert List to Map OR Try a different approach, Let's say using Map or Something else.

    • @SHREYATIWARI-lk5rc
      @SHREYATIWARI-lk5rc 11 หลายเดือนก่อน +1

      Sir , I also tried this there is same problem but I tried this approach and for me it is passing all possible test cases which I can think of. Please sir can you tell is it right...
      trigger CaseTrigger on Case(after insert){
      Map accIds = new Map ();
      for(Case c : trigger.new){
      if(c.AccountId != null){
      accIds.put(c.AccountId,c.CaseNumber);
      }
      }
      List accnts = [select id,latest_Case_Number__c from Account where id in :accIds.keySet()];
      for(Account acc : accnts){
      acc.latest_Case_Number__c = accIds.get(acc.Id);
      }
      update accnts;
      }

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

      @@SHREYATIWARI-lk5rc this one is the better approach