Great code until line 42. We are unnecessarily querying account again and looping it. We could have done it in 2-3 lines. You don’t need to query account again, you may create an instance and assign Id. Thanks.
@spblore2 ай бұрын
Instead of this approach may be we can try query and get Case records which are status closed there by we dont need OldMap in that case..and we can keep the count using aggregateresult..instead of loops?isnt it
@abhijeetvaishnab77382 ай бұрын
provide trigger operations also like in this case it shd be - trigger CaseTrigger on Case(after update,after delete,after undelete){}
@AnmolAgrawal-sc5ll10 ай бұрын
bro no doubt you are doing great but please give a good description of scenario here you are telling update accoun ton basis of closed cases so we are assuming it will be on account object you would have tp give better description like when we change or insert cases then update account this looses motivation bcoz our reasoning fails due to wrong questions
@prithviprasad3476 Жыл бұрын
Hello can you please let us know how you are getting this scenarios , if the questions are available in more content it will help to practice as our own as well
@sfdcninjas Жыл бұрын
Hi Prithvi, I have reached out to experienced professionals and individuals who have undergone interviews at various companies in order to gather insights and information regarding different scenarios.
@truthteller2237 Жыл бұрын
Can you also make videos on not only triggers but also on apex classes which are used for different functionalities. That will be very helpful.
@sfdcninjas Жыл бұрын
Hi , Yes i have that in my plan dont worry you wil get it soon
@BalajiBalaji-jv1gt Жыл бұрын
When aggregating the case object is it not possible to write sub query of account.?
@sfdcninjas Жыл бұрын
Hi buddy sorry for late reply actually it is not a good practice to use sub query
@shubhamsri.1895 Жыл бұрын
in my Case Status field CLOSED picklist is not showing. Only New, Working, Escalated is visible. How to view Closed option?
@sfdcninjas Жыл бұрын
Hi Shubham , I have already explained that issue in video please see from 14:00
@rajnishkumarsingh8110 Жыл бұрын
@sfdc ninja At what experience level do they ask this type of questions?
@sfdcninjas Жыл бұрын
Hi Rajnish , this question was asked to a person with 1.8 years of experience.
@rajnishkumarsingh8110 Жыл бұрын
@@sfdcninjas Thanks for reply :)
@hareeshaddanki7623 Жыл бұрын
Please Can you share code
@sfdcninjas Жыл бұрын
Hi Hareesh , all codes will be available on website soon don't worry.
@hareeshaddanki7623 Жыл бұрын
@@sfdcninjas thanks
@varikutivenkatesh6680 Жыл бұрын
Write a Test Class For that Triggers.
@sfdcninjas Жыл бұрын
Hi Venkatesh , yes buddy i have that in my plan there will be playlist of test classes for all trigger scenarios
@ankitdangre4790 Жыл бұрын
Same
@sfdcninjas Жыл бұрын
don’t worry guys there will be a series on test classes
@ankitdangre4790 Жыл бұрын
Sir plz make a video on interview questions asked in various IT companies .
@utkarshsoni79385 ай бұрын
Try the below one the below code will work in Bulk for the all the Trigger Scenario's. Trgr: -> ---- trigger AccountRatingTrgr on Case(after insert, after update, after delete, after undelete){ if(Trigger.isAfter){ if(Trigger.isUpdate){ AccountRatingTrgrCls.AccountRatingTrgrMethod(Trigger.New,Trigger.OldMap); }else if(Trigger.isDelete){ AccountRatingTrgrCls.AccountRatingTrgrMethod(Trigger.Old,null); }else{ AccountRatingTrgrCls.AccountRatingTrgrMethod(Trigger.New,null); } } } Modular Class: -> ------------- public class AccountRatingTrgrCls{ public static void AccountRatingTrgrMethod(List caseList,Map oldCaseMap){ String accountRating; Set setOfAccountIds = new Set(); Map accountMap = new Map(); List accountList = new List(); List accountListToUpdate = new List(); if(caseList!=null && caseList.size()>0){ for(Case cses : caseList){ if(cses.IsClosed__c){ if(oldCaseMap==null){ setOfAccountIds.add(cses.AccountId); }else{ if(cses.AccountId != oldCaseMap.get(cses.Id).AccountId){ setOfAccountIds.add(cses.AccountId); setOfAccountIds.add(oldCaseMap.get(cses.Id).AccountId); }else{ setOfAccountIds.add(cses.AccountId); } } } } if(setOfAccountIds.size()>0 && setOfAccountIds!=null){ for(AggregateResult agr : [Select AccountId, Count(Id) countOfCaseIds FROM Case WHERE AccountId IN: setOfAccountIds GROUP BY AccountId]){ accountMap.put((Id)agr.get('AccountId'),(Integer)agr.get('countOfCaseIds')); } } accountList = [Select Id,Rating FROM Account WHERE ID IN: setOfAccountIds]; System.debug('accountMap: '+accountMap); if(accountList.size()>0 && accountList!=null){ for(Account accounts : accountList){ if(!accountMap.isEmpty() && accountMap!=null){ accountRating=''; if(accountMap.containsKey(accounts.Id)){ if((Integer)accountMap.get(accounts.Id)==0){ accountRating = ''; }else if((Integer)accountMap.get(accounts.Id)>0 && (Integer)accountMap.get(accounts.Id)2 && (Integer)accountMap.get(accounts.Id)6){ accountRating = 'Hot'; } accountListToUpdate.add(new Account(Id=accounts.Id,Rating=(String)accountRating)); }else{ accountListToUpdate.add(new Account(Id=accounts.Id,Rating='')); } }else{ accountListToUpdate.add(new Account(Id=accounts.Id,Rating='')); } } } if(accountListToUpdate.size()>0 && accountListToUpdate!=null){ UPDATE accountListToUpdate; } } } }
@thesorcerer1113 ай бұрын
In your aggregate query you need to put IsClosed = true because the account can also contain open cases.