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
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/
5:44 sir in my trigger its shows that Illegal assignment from string to Decimal... What to to now ??
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?
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;
}
}
}
You are excellent guruji
amazing video series
Thank you Sir
Hi Sanjay Ji !!! Any update on the upcoming LWC playlist video.!!!
Iam getting List index out of bound by following the above process mentioned in the video
Can anyone please help me ,I'm writing the same code but still test case failed, actual is showing null
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!
check events in trigger by default its before events change to after
@@bandaruchaitanya2038in my case its hows illegal statement string to decimal , wht to do in version 58
@@ronnygamerz88 change your field(latestcasenumber) datatype to text
this code is not working when we try to create cases in bulk for a particular account.
@SanjayGuptaTechSchool
So in bulk case the one which gets inserted last that case number will be populated.
@@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.
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;
}
@@SHREYATIWARI-lk5rc this one is the better approach